Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,24 +55,13 @@ def generate_solutions_from_task(task):
|
|
| 55 |
5. 挑战与解决方案: (在实现过程中可能遇到的问题和解决方法)
|
| 56 |
|
| 57 |
任务: {task}"""
|
| 58 |
-
response = taskgen_client.predict(message=message, api_name="/chat")
|
| 59 |
|
| 60 |
-
#
|
|
|
|
| 61 |
print("原始响应内容:", response)
|
| 62 |
|
| 63 |
-
#
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
# 输出提取的方案内容,方便调试
|
| 67 |
-
print("提取的方案内容:", solutions)
|
| 68 |
-
|
| 69 |
-
if len(solutions) < 3:
|
| 70 |
-
return response.strip(), "(解析失败,显示原始回复)", ""
|
| 71 |
-
|
| 72 |
-
s1 = solutions[0].strip()
|
| 73 |
-
s2 = solutions[1].strip()
|
| 74 |
-
s3 = solutions[2].strip()
|
| 75 |
-
return s1, s2, s3
|
| 76 |
|
| 77 |
# 构建 Gradio UI
|
| 78 |
def build_ui():
|
|
@@ -84,52 +73,3 @@ def build_ui():
|
|
| 84 |
generate_task_btn = gr.Button("🧠 拆解 JD 成任务")
|
| 85 |
|
| 86 |
generate_solutions_btn = gr.Button("🚀 基于任务生成三个方案")
|
| 87 |
-
sol1 = gr.Textbox(label="方案1 / 或原始回复", lines=10, interactive=False)
|
| 88 |
-
sol2 = gr.Textbox(label="方案2", lines=10, interactive=False)
|
| 89 |
-
sol3 = gr.Textbox(label="方案3", lines=10, interactive=False)
|
| 90 |
-
|
| 91 |
-
select_radio = gr.Radio(choices=["1", "2", "3"], label="请选择你最满意的解决方案编号")
|
| 92 |
-
|
| 93 |
-
comment = gr.Textbox(lines=4, label="📝 请对选择的方案填写选择理由或批注该方案的优缺点")
|
| 94 |
-
|
| 95 |
-
user_solution = gr.Textbox(lines=6, label="📄 填写你自己的解决方案(可选)")
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
submit = gr.Button("✅ 提交 RLHF 数据")
|
| 99 |
-
feedback = gr.Textbox(label="系统反馈", interactive=False)
|
| 100 |
-
|
| 101 |
-
task_state = gr.State()
|
| 102 |
-
|
| 103 |
-
def handle_task_gen(jd_text):
|
| 104 |
-
task = extract_task_from_jd(jd_text)
|
| 105 |
-
return task, task
|
| 106 |
-
|
| 107 |
-
def handle_solutions_gen(task_text):
|
| 108 |
-
s1, s2, s3 = generate_solutions_from_task(task_text)
|
| 109 |
-
return s1, s2, s3
|
| 110 |
-
|
| 111 |
-
def handle_submit(selected_idx, user_input_text, comment_text, task_text):
|
| 112 |
-
record = {
|
| 113 |
-
"task": task_text,
|
| 114 |
-
"selected_index": selected_idx,
|
| 115 |
-
"user_solution": user_input_text,
|
| 116 |
-
"comment": comment_text,
|
| 117 |
-
"timestamp": datetime.now().isoformat()
|
| 118 |
-
}
|
| 119 |
-
try:
|
| 120 |
-
with open("rlhf_jd_data.jsonl", "a", encoding="utf-8") as f:
|
| 121 |
-
json.dump(record, f, ensure_ascii=False)
|
| 122 |
-
f.write("\n")
|
| 123 |
-
return f"✅ 数据已保存,选择方案 {selected_idx}"
|
| 124 |
-
except Exception as e:
|
| 125 |
-
return f"❌ 保存失败:{str(e)}"
|
| 126 |
-
|
| 127 |
-
generate_task_btn.click(fn=handle_task_gen, inputs=[jd_input], outputs=[task_output, task_state])
|
| 128 |
-
generate_solutions_btn.click(fn=handle_solutions_gen, inputs=[task_state], outputs=[sol1, sol2, sol3])
|
| 129 |
-
submit.click(fn=handle_submit, inputs=[select_radio, user_solution, comment, task_state], outputs=[feedback])
|
| 130 |
-
|
| 131 |
-
return demo
|
| 132 |
-
|
| 133 |
-
if __name__ == "__main__":
|
| 134 |
-
demo = build_ui()
|
| 135 |
-
demo.launch()
|
|
|
|
| 55 |
5. 挑战与解决方案: (在实现过程中可能遇到的问题和解决方法)
|
| 56 |
|
| 57 |
任务: {task}"""
|
|
|
|
| 58 |
|
| 59 |
+
# 直接输出原始响应内容以便调试
|
| 60 |
+
response = taskgen_client.predict(message=message, api_name="/chat")
|
| 61 |
print("原始响应内容:", response)
|
| 62 |
|
| 63 |
+
# 直接返回响应内容,便于分析
|
| 64 |
+
return response.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# 构建 Gradio UI
|
| 67 |
def build_ui():
|
|
|
|
| 73 |
generate_task_btn = gr.Button("🧠 拆解 JD 成任务")
|
| 74 |
|
| 75 |
generate_solutions_btn = gr.Button("🚀 基于任务生成三个方案")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|