Sonu313131 commited on
Commit
582b41a
·
verified ·
1 Parent(s): 4d674d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -43
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
- try:
50
- # Full prompt with required system instructions
51
- system_prompt = (
52
- "You are a general AI assistant. I will ask you a question. "
53
- "Report your thoughts, and finish your answer with the following template: "
54
- "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. "
55
- "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. "
56
- "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. "
57
- "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"
58
- )
59
- full_prompt = system_prompt + f"Question: {question_text.strip()}"
60
-
61
- # Run agent with full prompt
62
- loop = asyncio.get_event_loop()
63
- agent_response = await loop.run_in_executor(None, agent, full_prompt)
64
-
65
- # Try to extract FINAL ANSWER
66
- if "FINAL ANSWER:" in agent_response:
67
- _, final_answer = agent_response.rsplit("FINAL ANSWER:", 1)
68
- final_answer = final_answer.strip()
69
- else:
70
- final_answer = agent_response.strip()
71
-
72
- answers_payload.append({
73
- "task_id": task_id,
74
- "model_answer": final_answer
75
- })
76
-
77
- results_log.append({
78
- "Task ID": task_id,
79
- "Question": question_text,
80
- "Submitted Answer": final_answer
81
- })
82
-
83
- except Exception as e:
84
- print(f"Error running agent on task {task_id}: {e}")
85
- results_log.append({
86
- "Task ID": task_id,
87
- "Question": question_text,
88
- "Submitted Answer": f"AGENT ERROR: {e}"
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)