Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
-
from datetime import datetime
|
4 |
from gradio_client import Client
|
5 |
-
import re
|
6 |
import json
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
|
11 |
# 输出文件夹
|
12 |
OUTPUT_DIR = "outputs"
|
@@ -19,8 +17,8 @@ def extract_task_from_jd(jd):
|
|
19 |
任务:(任务描述)
|
20 |
|
21 |
JD: {jd}"""
|
22 |
-
response =
|
23 |
-
return response.strip()
|
24 |
|
25 |
# 基于任务生成三个解决方案
|
26 |
def generate_solutions_from_task(task):
|
@@ -31,10 +29,10 @@ def generate_solutions_from_task(task):
|
|
31 |
方案3:(内容)
|
32 |
|
33 |
任务: {task}"""
|
34 |
-
response =
|
35 |
-
solutions =
|
36 |
if len(solutions) < 3:
|
37 |
-
return response
|
38 |
s1 = solutions[0].strip()
|
39 |
s2 = solutions[1].strip()
|
40 |
s3 = solutions[2].strip()
|
@@ -45,24 +43,19 @@ def build_ui():
|
|
45 |
with gr.Blocks() as demo:
|
46 |
gr.Markdown("## 📌 JD 任务拆解 + 解决方案选择 Demo")
|
47 |
|
48 |
-
#
|
49 |
jd_input = gr.Textbox(label="输入 JD", placeholder="请输入岗位描述 JD")
|
50 |
task_output = gr.Textbox(label="拆解出的测试任务", lines=2, interactive=False)
|
51 |
generate_task_btn = gr.Button("🧠 拆解 JD 成任务")
|
52 |
|
53 |
-
#
|
54 |
generate_solutions_btn = gr.Button("🚀 基于任务生成三个方案")
|
55 |
-
sol1 = gr.Textbox(label="方案1
|
56 |
sol2 = gr.Textbox(label="方案2", lines=10, interactive=False)
|
57 |
sol3 = gr.Textbox(label="方案3", lines=10, interactive=False)
|
58 |
|
59 |
-
# 选择最满意的方案编号
|
60 |
select_radio = gr.Radio(choices=["1", "2", "3"], label="请选择你最满意的解决方案编号")
|
61 |
|
62 |
-
# 用户对选择方案的评论
|
63 |
-
comment = gr.Textbox(lines=4, label="📝 请对选择的方案填写选择理由或批注该方案的优缺点")
|
64 |
-
user_solution = gr.Textbox(lines=6, label="📄 填写你自己的解决方案(可选)")
|
65 |
-
|
66 |
# 提交按钮
|
67 |
submit = gr.Button("✅ 提交 RLHF 数据")
|
68 |
feedback = gr.Textbox(label="系统反馈", interactive=False)
|
@@ -79,7 +72,7 @@ def build_ui():
|
|
79 |
s1, s2, s3 = generate_solutions_from_task(task_text)
|
80 |
return s1, s2, s3
|
81 |
|
82 |
-
#
|
83 |
def handle_submit(selected_idx, user_input_text, comment_text, task_text):
|
84 |
record = {
|
85 |
"task": task_text,
|
@@ -96,13 +89,14 @@ def build_ui():
|
|
96 |
except Exception as e:
|
97 |
return f"❌ 保存失败:{str(e)}"
|
98 |
|
99 |
-
#
|
100 |
generate_task_btn.click(fn=handle_task_gen, inputs=[jd_input], outputs=[task_output, task_state])
|
101 |
generate_solutions_btn.click(fn=handle_solutions_gen, inputs=[task_state], outputs=[sol1, sol2, sol3])
|
102 |
submit.click(fn=handle_submit, inputs=[select_radio, user_solution, comment, task_state], outputs=[feedback])
|
103 |
|
104 |
return demo
|
105 |
|
|
|
106 |
if __name__ == "__main__":
|
107 |
demo = build_ui()
|
108 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from gradio_client import Client
|
|
|
3 |
import json
|
4 |
+
from datetime import datetime
|
5 |
|
6 |
+
# 使用 Hugging Face 提供的 Qwen 模型 API 端点
|
7 |
+
client = Client("https://qwen-qwen-72b-chat-demo.hf.space/--replicas/ypz66/")
|
8 |
|
9 |
# 输出文件夹
|
10 |
OUTPUT_DIR = "outputs"
|
|
|
17 |
任务:(任务描述)
|
18 |
|
19 |
JD: {jd}"""
|
20 |
+
response = client.predict([message], api_name="/model_chat")
|
21 |
+
return response[0].strip()
|
22 |
|
23 |
# 基于任务生成三个解决方案
|
24 |
def generate_solutions_from_task(task):
|
|
|
29 |
方案3:(内容)
|
30 |
|
31 |
任务: {task}"""
|
32 |
+
response = client.predict([message], api_name="/model_chat")
|
33 |
+
solutions = response[0].split("\n")
|
34 |
if len(solutions) < 3:
|
35 |
+
return response[0], "(解析失败,显示原始回复)", ""
|
36 |
s1 = solutions[0].strip()
|
37 |
s2 = solutions[1].strip()
|
38 |
s3 = solutions[2].strip()
|
|
|
43 |
with gr.Blocks() as demo:
|
44 |
gr.Markdown("## 📌 JD 任务拆解 + 解决方案选择 Demo")
|
45 |
|
46 |
+
# 输入 JD
|
47 |
jd_input = gr.Textbox(label="输入 JD", placeholder="请输入岗位描述 JD")
|
48 |
task_output = gr.Textbox(label="拆解出的测试任务", lines=2, interactive=False)
|
49 |
generate_task_btn = gr.Button("🧠 拆解 JD 成任务")
|
50 |
|
51 |
+
# 生成解决方案
|
52 |
generate_solutions_btn = gr.Button("🚀 基于任务生成三个方案")
|
53 |
+
sol1 = gr.Textbox(label="方案1", lines=10, interactive=False)
|
54 |
sol2 = gr.Textbox(label="方案2", lines=10, interactive=False)
|
55 |
sol3 = gr.Textbox(label="方案3", lines=10, interactive=False)
|
56 |
|
|
|
57 |
select_radio = gr.Radio(choices=["1", "2", "3"], label="请选择你最满意的解决方案编号")
|
58 |
|
|
|
|
|
|
|
|
|
59 |
# 提交按钮
|
60 |
submit = gr.Button("✅ 提交 RLHF 数据")
|
61 |
feedback = gr.Textbox(label="系统反馈", interactive=False)
|
|
|
72 |
s1, s2, s3 = generate_solutions_from_task(task_text)
|
73 |
return s1, s2, s3
|
74 |
|
75 |
+
# 提交反馈
|
76 |
def handle_submit(selected_idx, user_input_text, comment_text, task_text):
|
77 |
record = {
|
78 |
"task": task_text,
|
|
|
89 |
except Exception as e:
|
90 |
return f"❌ 保存失败:{str(e)}"
|
91 |
|
92 |
+
# 绑定按钮事件
|
93 |
generate_task_btn.click(fn=handle_task_gen, inputs=[jd_input], outputs=[task_output, task_state])
|
94 |
generate_solutions_btn.click(fn=handle_solutions_gen, inputs=[task_state], outputs=[sol1, sol2, sol3])
|
95 |
submit.click(fn=handle_submit, inputs=[select_radio, user_solution, comment, task_state], outputs=[feedback])
|
96 |
|
97 |
return demo
|
98 |
|
99 |
+
# 启动 Gradio 应用
|
100 |
if __name__ == "__main__":
|
101 |
demo = build_ui()
|
102 |
demo.launch()
|