Update app.py
Browse files
app.py
CHANGED
@@ -40,54 +40,54 @@ async def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
40 |
|
41 |
results_log = []
|
42 |
answers_payload = []
|
|
|
|
|
43 |
for item in questions_data:
|
44 |
task_id = item.get("task_id")
|
45 |
question_text = item.get("question")
|
46 |
if not task_id or question_text is None:
|
47 |
continue
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
})
|
90 |
-
|
91 |
|
92 |
if not answers_payload:
|
93 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
@@ -144,4 +144,4 @@ if __name__ == "__main__":
|
|
144 |
print(f"✅ SPACE_ID: https://huggingface.co/spaces/{space_id_startup}")
|
145 |
|
146 |
print("Launching Gradio Interface...")
|
147 |
-
demo.launch(debug=True, share=False)
|
|
|
40 |
|
41 |
results_log = []
|
42 |
answers_payload = []
|
43 |
+
loop = asyncio.get_event_loop()
|
44 |
+
|
45 |
for item in questions_data:
|
46 |
task_id = item.get("task_id")
|
47 |
question_text = item.get("question")
|
48 |
if not task_id or question_text is None:
|
49 |
continue
|
50 |
|
51 |
+
try:
|
52 |
+
system_prompt = (
|
53 |
+
"You are a general AI assistant. I will ask you a question. "
|
54 |
+
"Report your thoughts, and finish your answer with the following template: "
|
55 |
+
"FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
|
56 |
+
"If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
|
57 |
+
"If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. "
|
58 |
+
"If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n\n"
|
59 |
+
)
|
60 |
+
full_prompt = system_prompt + f"Question: {question_text.strip()}"
|
61 |
+
|
62 |
+
agent_result = await loop.run_in_executor(None, agent, full_prompt)
|
63 |
+
|
64 |
+
# Try to extract final answer depending on type of result
|
65 |
+
if isinstance(agent_result, dict) and "final_answer" in agent_result:
|
66 |
+
final_answer = str(agent_result["final_answer"]).strip()
|
67 |
+
elif isinstance(agent_result, str) and "FINAL ANSWER:" in agent_result:
|
68 |
+
_, final_answer = agent_result.rsplit("FINAL ANSWER:", 1)
|
69 |
+
final_answer = final_answer.strip()
|
70 |
+
else:
|
71 |
+
final_answer = str(agent_result).strip()
|
72 |
+
|
73 |
+
answers_payload.append({
|
74 |
+
"task_id": task_id,
|
75 |
+
"model_answer": final_answer
|
76 |
+
})
|
77 |
+
|
78 |
+
results_log.append({
|
79 |
+
"Task ID": task_id,
|
80 |
+
"Question": question_text,
|
81 |
+
"Submitted Answer": final_answer
|
82 |
+
})
|
83 |
+
|
84 |
+
except Exception as e:
|
85 |
+
print(f"Error running agent on task {task_id}: {e}")
|
86 |
+
results_log.append({
|
87 |
+
"Task ID": task_id,
|
88 |
+
"Question": question_text,
|
89 |
+
"Submitted Answer": f"AGENT ERROR: {e}"
|
90 |
+
})
|
|
|
|
|
91 |
|
92 |
if not answers_payload:
|
93 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
|
|
144 |
print(f"✅ SPACE_ID: https://huggingface.co/spaces/{space_id_startup}")
|
145 |
|
146 |
print("Launching Gradio Interface...")
|
147 |
+
demo.launch(debug=True, share=False)
|