上传文件至 /
This commit is contained in:
parent
1762d6904b
commit
dc90261bb5
89
README.md
Normal file
89
README.md
Normal file
@ -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 技术的实际应用有了更加清晰和理性的认识。
|
||||||
41
app.py
Normal file
41
app.py
Normal file
@ -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)
|
||||||
43
index.html
Normal file
43
index.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>AI 写作助手</title>
|
||||||
|
<link rel="stylesheet" href="/static/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>📝 AI 写作助手</h1>
|
||||||
|
<p class="subtitle">基于通义千问的智能文本润色系统</p>
|
||||||
|
|
||||||
|
<textarea id="inputText" placeholder="请输入需要润色的文本..."></textarea>
|
||||||
|
|
||||||
|
<button onclick="rewriteText()">开始润色</button>
|
||||||
|
|
||||||
|
<div class="result-box">
|
||||||
|
<h3>✨ AI 输出结果</h3>
|
||||||
|
<div id="resultText">等待输入...</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function rewriteText() {
|
||||||
|
const text = document.getElementById("inputText").value;
|
||||||
|
|
||||||
|
fetch("/rewrite", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ text: text })
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
document.getElementById("resultText").innerText = data.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
BIN
requirements.txt
Normal file
BIN
requirements.txt
Normal file
Binary file not shown.
68
style.css
Normal file
68
style.css
Normal file
@ -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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user