删除 app.py
This commit is contained in:
parent
dc90261bb5
commit
cc71c39d41
41
app.py
41
app.py
@ -1,41 +0,0 @@
|
||||
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)
|
||||
Loading…
Reference in New Issue
Block a user