diff --git a/README.md b/README.md new file mode 100644 index 0000000..e9d2e09 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +# AI 写作助手(AI Writing Assistant) + +--- + +## 2.1 团队成员与贡献 + +| 姓名 | 学号 | 主要贡献(具体分工) | +|----|----|----------------| +| 索梦露 | 2411020218 | (组长)项目整体设计、后端核心逻辑开发、编写 | +| 李秀芬 | 2411020130 | Web 前端界面设计、页面样式美化、 | + +--- + +## 2.2 项目简介 & 运行指南 + +### 简介 + +本项目是一个基于 Python 和大语言模型 API 的 **AI 写作助手系统**, +旨在解决学生和内容创作者在日常写作中 **表达不够通顺、反复修改效率低** 的问题。 +用户只需输入原始文本,即可通过 AI 自动生成更加流畅、自然的改写结果,从而提升写作效率和质量。 + +--- + +### 如何运行 +```bash +# 1️⃣ 安装依赖 +pip install -r requirements.txt +# 2️⃣ 配置 API Key +#在 .env 中填写你的 API Key,例如: +DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxxxxx +#3️⃣ 启动项目 +python app.py +#启动成功后,在浏览器中访问 +http://127.0.0.1:5000 +#即可打开 AI 写作助手网页界面并进行演示 +``` +--- +## 2.3 开发心得 +### 选题思考:为什么做这个?解决了谁的痛苦? +#### 在日常学习和课程作业中,我们经常需要撰写实验报告、课程设计说明或总结性文字。 +很多时候,并不是没有想法,而是**不知道如何把想法组织成通顺、专业的文字**, +往往需要反复修改,耗费大量时间。 + +因此,我们选择了“AI 写作助手”作为课程设计题目,希望借助当前大语言模型在自然语言处理方面的能力, +为学生和内容创作者提供一个**低门槛、易使用、效果直观**的写作辅助工具, +帮助用户提升写作效率,减少无意义的重复修改。 + +### AI 协作体验 +这是我们第一次在完整项目中深度使用 AI 来协助编程和功能设计。 + +在开发过程中,AI 在以下方面给予了非常大的帮助: + +1.后端接口逻辑的设计思路 + +2.Prompt 的不断优化与改进 + +3.前后端交互流程的梳理 + +4.常见错误的快速定位与修复 + +其中,让人直呼“牛逼”的 Prompt 是: + +“请帮我润色以下文本,使其更加通顺自然,语气正式但不过于生硬。” + +这一 Prompt 能够在多种输入情况下稳定输出高质量文本,极大提升了系统实用性。 + +但也并非所有时候都一帆风顺。有时由于 Prompt 描述不够明确, +AI 会输出偏离预期的内容,或者在代码细节上出现不符合实际环境的问题, +这时就需要人工不断尝试、调整和验证,甚至“推翻重来”,这一过程也让我们更加理解了 +**“如何正确地向 AI 提问”本身就是一项重要能力。** + +### 自我反思:AI 时代,程序员的核心竞争力是什么? +通过本次课程设计,我们逐渐意识到: + +在 AI 时代,程序员的核心竞争力并不是死记硬背语法,而是: + +问题拆解能力 —— 能否把一个模糊需求拆解成清晰的模块 + +工程思维 —— 是否具备代码结构、项目规范和安全意识 + +Prompt 设计能力 —— 是否能高效地与 AI 协作 + +判断与验证能力 —— 是否能判断 AI 给出的结果是否合理、可用 + +AI 并不会取代程序员,但会放大程序员之间的差距。 +只有真正理解需求、善于思考并具备持续学习能力的人, +才能在 AI 时代持续保持竞争力。 + +本次项目不仅锻炼了我们的 Python 编程能力,也让我们对 AI 技术的实际应用有了更加清晰和理性的认识。 \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..fcb951a --- /dev/null +++ b/app.py @@ -0,0 +1,41 @@ +from flask import Flask, render_template, request, jsonify +import dashscope +from dashscope import Generation + +app = Flask(__name__) + +# ========================== +# 配置通义千问 API Key +# ========================== +dashscope.api_key = "sk-27ec095dc16a49ef84536e0a6e2452bf" + + +def ai_rewrite(text): + prompt = f"请帮我润色以下文本,使其更加通顺自然:{text}" + + response = Generation.call( + model="qwen-turbo", + prompt=prompt + ) + + if response.status_code == 200: + return response.output.text + else: + return "AI 接口调用失败,请稍后重试" + + +@app.route("/") +def index(): + return render_template("index.html") + + +@app.route("/rewrite", methods=["POST"]) +def rewrite(): + data = request.json + text = data.get("text", "") + result = ai_rewrite(text) + return jsonify({"result": result}) + + +if __name__ == "__main__": + app.run(debug=True) diff --git a/index.html b/index.html new file mode 100644 index 0000000..db1f4a0 --- /dev/null +++ b/index.html @@ -0,0 +1,43 @@ + + + + + AI 写作助手 + + + + +
+

📝 AI 写作助手

+

基于通义千问的智能文本润色系统

+ + + + + +
+

✨ AI 输出结果

+
等待输入...
+
+
+ + + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..9bb8cdc Binary files /dev/null and b/requirements.txt differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..f31d8b3 --- /dev/null +++ b/style.css @@ -0,0 +1,68 @@ +body { + margin: 0; + font-family: "Segoe UI", "PingFang SC", sans-serif; + background: linear-gradient(135deg, #4facfe, #00f2fe); + height: 100vh; + display: flex; + justify-content: center; + align-items: center; +} + +.container { + background: #ffffff; + width: 600px; + padding: 30px; + border-radius: 16px; + box-shadow: 0 20px 40px rgba(0,0,0,0.2); +} + +h1 { + text-align: center; + margin-bottom: 5px; +} + +.subtitle { + text-align: center; + color: #666; + margin-bottom: 20px; +} + +textarea { + width: 100%; + height: 120px; + padding: 12px; + font-size: 14px; + border-radius: 8px; + border: 1px solid #ccc; + resize: none; + box-sizing: border-box; +} + +button { + width: 100%; + margin-top: 15px; + padding: 12px; + background: #4facfe; + border: none; + color: white; + font-size: 16px; + border-radius: 8px; + cursor: pointer; +} + +button:hover { + background: #00c6fb; +} + +.result-box { + margin-top: 25px; + padding: 15px; + background: #f7f9fc; + border-radius: 8px; +} + +#resultText { + margin-top: 10px; + color: #333; + white-space: pre-wrap; +}