Samuel Thomas commited on
Commit
b395607
·
1 Parent(s): ad021fc

setup app for submission

Browse files
Files changed (1) hide show
  1. app.py +17 -38
app.py CHANGED
@@ -88,51 +88,31 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
88
  print(f"Error creating new states: {tb_str}")
89
  return f"Error creating new states: {tb_str}", None
90
 
91
- # 3. Setup states for questions
92
- try:
93
- ans = []
94
- for r in range(len(hf_questions)):
95
  s = State(question = hf_questions[r]['question'],
96
  input_file = hf_questions[r]['input_file'],
97
  file_type = hf_questions[r]['file_type'],
98
  file_path = hf_questions[r]['file_path'])
99
- print(s['question'])
100
- #temp_ans = intelligent_agent(s)
101
- #print(temp_ans)
102
- print('\n')
103
- #ans.append(temp_ans)
104
- except Exception as e:
105
- tb_str = traceback.format_exc()
106
- print(f"Error setting up states: {tb_str}")
107
- return f"Error setting up states: {tb_str}", None
108
- # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
109
- agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
110
- print(agent_code)
111
-
112
-
113
-
114
- """
115
- # 3. Run your Agent
116
- results_log = []
117
- answers_payload = []
118
- print(f"Running agent on {len(questions_data)} questions...")
119
- for item in questions_data:
120
- task_id = item.get("task_id")
121
- question_text = item.get("question")
122
- if not task_id or question_text is None:
123
- print(f"Skipping item with missing task_id or question: {item}")
124
- continue
125
- try:
126
- submitted_answer = agent(question_text)
127
- answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
128
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
129
- except Exception as e:
130
- print(f"Error running agent on task {task_id}: {e}")
131
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
132
 
133
  if not answers_payload:
134
  print("Agent did not produce any answers to submit.")
135
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
 
 
 
 
136
 
137
  # 4. Prepare Submission
138
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
@@ -181,7 +161,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
181
  print(status_message)
182
  results_df = pd.DataFrame(results_log)
183
  return status_message, results_df
184
- """
185
 
186
  # --- Build Gradio Interface using Blocks ---
187
  with gr.Blocks() as demo:
 
88
  print(f"Error creating new states: {tb_str}")
89
  return f"Error creating new states: {tb_str}", None
90
 
91
+ # 3. Setup states for questions and run agent
92
+ answers_payload = []
93
+ results_log = []
94
+ for r in range(len(hf_questions)):
95
  s = State(question = hf_questions[r]['question'],
96
  input_file = hf_questions[r]['input_file'],
97
  file_type = hf_questions[r]['file_type'],
98
  file_path = hf_questions[r]['file_path'])
99
+ try:
100
+ task_id = hf_questions[r]['task_id']
101
+ question_text = hf_questions[r]['question']
102
+ submitted_answer = intelligent_agent(s)
103
+ answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
104
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
105
+ except:
106
+ print(f"Error running agent on task {task_id}: {e}")
107
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  if not answers_payload:
110
  print("Agent did not produce any answers to submit.")
111
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
112
+
113
+ # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
114
+ agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
115
+ print(agent_code)
116
 
117
  # 4. Prepare Submission
118
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
 
161
  print(status_message)
162
  results_df = pd.DataFrame(results_log)
163
  return status_message, results_df
 
164
 
165
  # --- Build Gradio Interface using Blocks ---
166
  with gr.Blocks() as demo: