Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import json
|
4 |
+
|
5 |
+
# 你的 OpenAI API Key(如果用 Hugging Face 模型可以换掉)
|
6 |
+
OPENAI_API_KEY = "你的 OpenAI API Key"
|
7 |
+
|
8 |
+
def generate_task_structure(prompt):
|
9 |
+
"""
|
10 |
+
解析用户输入,生成任务结构
|
11 |
+
"""
|
12 |
+
response = openai.ChatCompletion.create(
|
13 |
+
model="gpt-4", # 或 "gpt-3.5-turbo"
|
14 |
+
messages=[
|
15 |
+
{"role": "system", "content": "你是一个智能项目管理 AI,帮助用户从想法生成任务结构。"},
|
16 |
+
{"role": "user", "content": f"根据这个想法生成任务管理 JSON 结构:{prompt}"}
|
17 |
+
],
|
18 |
+
api_key=OPENAI_API_KEY
|
19 |
+
)
|
20 |
+
|
21 |
+
# 获取 AI 返回的文本
|
22 |
+
ai_text = response["choices"][0]["message"]["content"]
|
23 |
+
|
24 |
+
# 尝试解析 JSON
|
25 |
+
try:
|
26 |
+
task_structure = json.loads(ai_text)
|
27 |
+
except json.JSONDecodeError:
|
28 |
+
task_structure = {"error": "AI 生成的结果不是有效的 JSON,请调整提示词。"}
|
29 |
+
|
30 |
+
return json.dumps(task_structure, indent=2, ensure_ascii=False)
|
31 |
+
|
32 |
+
# Gradio UI
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("# 🧠 AI 任务管理助手")
|
35 |
+
gr.Markdown("输入你的想法,让 AI 生成 **目标 -> 任务 -> 里程碑 -> 排期**")
|
36 |
+
|
37 |
+
user_input = gr.Textbox(label="输入你的想法", placeholder="例如:我想开发一个 AI 机器人")
|
38 |
+
output_text = gr.Textbox(label="AI 生成的任务", lines=10)
|
39 |
+
|
40 |
+
submit_button = gr.Button("生成任务")
|
41 |
+
submit_button.click(fn=generate_task_structure, inputs=user_input, outputs=output_text)
|
42 |
+
|
43 |
+
demo.launch()
|