Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -37,4 +37,97 @@ def generate_solutions_from_task(task):
|
|
37 |
|
38 |
请严格按如下格式输出,每个方案应包含详细信息,字数不少于200字:
|
39 |
方案1:
|
40 |
-
1. 总体思路:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
请严格按如下格式输出,每个方案应包含详细信息,字数不少于200字:
|
39 |
方案1:
|
40 |
+
1. 总体思路: (简述方案的总体设计思想)
|
41 |
+
2. 执行步骤: (具体的实现步骤,最好有分步)
|
42 |
+
3. 技术栈: (技术栈、工具、框架)
|
43 |
+
4. 代码示例: (如果适用,提供相关代码片段)
|
44 |
+
5. 挑战与解决方案: (在实现过程中可能遇到的问题和解决方法)
|
45 |
+
|
46 |
+
方案2:
|
47 |
+
1. 总体思路: (简述方案的总体设计思想)
|
48 |
+
2. 执行步骤: (具体的实现步骤,最好有分步)
|
49 |
+
3. 技术栈: (技术栈、工具、框架)
|
50 |
+
4. 代码示例: (如果适用,提供相关代码片段)
|
51 |
+
5. 挑战与解决方案: (在实现过程中可能遇到的问题和解决方法)
|
52 |
+
|
53 |
+
方案3:
|
54 |
+
1. 总体思路: (简述方案的总体设计思想)
|
55 |
+
2. 执行步骤: (具体的实现步骤,最好有分步)
|
56 |
+
3. 技术栈: (技术栈、工具、框架)
|
57 |
+
4. 代码示例: (如果适用,提供相关代码片段)
|
58 |
+
5. 挑战与解决方案: (在实现过程中可能遇到的问题和解决方法)
|
59 |
+
|
60 |
+
任务: {task}"""
|
61 |
+
|
62 |
+
response = taskgen_client.predict(message=message, api_name="/chat")
|
63 |
+
|
64 |
+
# 提取方案的详细内容
|
65 |
+
solutions = re.findall(r"方案[123][::]\s*(.*?)(?=\n|方案[123][::]|$)", response, re.DOTALL)
|
66 |
+
|
67 |
+
if len(solutions) < 3:
|
68 |
+
return response.strip(), "(解析失败,显示原始回复)", ""
|
69 |
+
|
70 |
+
s1 = solutions[0].strip()
|
71 |
+
s2 = solutions[1].strip()
|
72 |
+
s3 = solutions[2].strip()
|
73 |
+
return s1, s2, s3
|
74 |
+
|
75 |
+
# 构建 Gradio UI
|
76 |
+
def build_ui():
|
77 |
+
with gr.Blocks() as demo:
|
78 |
+
gr.Markdown("## 📌 JD 任务拆解 + 解决方案选择 Demo")
|
79 |
+
|
80 |
+
jd_input = gr.Textbox(label="输入 JD", placeholder="请输入岗位描述 JD")
|
81 |
+
task_output = gr.Textbox(label="拆解出的测试任务", lines=2, interactive=False)
|
82 |
+
generate_task_btn = gr.Button("🧠 拆解 JD 成任务")
|
83 |
+
|
84 |
+
generate_solutions_btn = gr.Button("🚀 基于任务生成三个方案")
|
85 |
+
sol1 = gr.Textbox(label="方案1 / 或原始回复", lines=10, interactive=False)
|
86 |
+
sol2 = gr.Textbox(label="方案2", lines=10, interactive=False)
|
87 |
+
sol3 = gr.Textbox(label="方案3", lines=10, interactive=False)
|
88 |
+
|
89 |
+
select_radio = gr.Radio(choices=["1", "2", "3"], label="请选择你最满意的解决方案编号")
|
90 |
+
|
91 |
+
comment = gr.Textbox(lines=4, label="📝 请对选择的方案填写选择理由或批注该方案的优缺点")
|
92 |
+
|
93 |
+
user_solution = gr.Textbox(lines=6, label="📄 填写你自己的解决方案(可选)")
|
94 |
+
|
95 |
+
|
96 |
+
submit = gr.Button("✅ 提交 RLHF 数据")
|
97 |
+
feedback = gr.Textbox(label="系统反馈", interactive=False)
|
98 |
+
|
99 |
+
task_state = gr.State()
|
100 |
+
|
101 |
+
def handle_task_gen(jd_text):
|
102 |
+
task = extract_task_from_jd(jd_text)
|
103 |
+
return task, task
|
104 |
+
|
105 |
+
def handle_solutions_gen(task_text):
|
106 |
+
s1, s2, s3 = generate_solutions_from_task(task_text)
|
107 |
+
return s1, s2, s3
|
108 |
+
|
109 |
+
def handle_submit(selected_idx, user_input_text, comment_text, task_text):
|
110 |
+
record = {
|
111 |
+
"task": task_text,
|
112 |
+
"selected_index": selected_idx,
|
113 |
+
"user_solution": user_input_text,
|
114 |
+
"comment": comment_text,
|
115 |
+
"timestamp": datetime.now().isoformat()
|
116 |
+
}
|
117 |
+
try:
|
118 |
+
with open("rlhf_jd_data.jsonl", "a", encoding="utf-8") as f:
|
119 |
+
json.dump(record, f, ensure_ascii=False)
|
120 |
+
f.write("\n")
|
121 |
+
return f"✅ 数据已保存,选择方案 {selected_idx}"
|
122 |
+
except Exception as e:
|
123 |
+
return f"❌ 保存失败:{str(e)}"
|
124 |
+
|
125 |
+
generate_task_btn.click(fn=handle_task_gen, inputs=[jd_input], outputs=[task_output, task_state])
|
126 |
+
generate_solutions_btn.click(fn=handle_solutions_gen, inputs=[task_state], outputs=[sol1, sol2, sol3])
|
127 |
+
submit.click(fn=handle_submit, inputs=[select_radio, user_solution, comment, task_state], outputs=[feedback])
|
128 |
+
|
129 |
+
return demo
|
130 |
+
|
131 |
+
if __name__ == "__main__":
|
132 |
+
demo = build_ui()
|
133 |
+
demo.launch()
|