sampsong commited on
Commit
5e054ff
·
1 Parent(s): 2643fe3
Files changed (1) hide show
  1. app.py +59 -63
app.py CHANGED
@@ -57,74 +57,70 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
57
  # 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)
58
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
59
  print(agent_code)
60
-
61
- # 2. Fetch Questions
62
- print(f"Fetching questions from: {questions_url}")
63
- try:
64
- response = requests.get(questions_url, timeout=15)
65
- response.raise_for_status()
66
- questions_data = response.json()
67
- if not questions_data:
68
- print("Fetched questions list is empty.")
69
- return "Fetched questions list is empty or invalid format.", None
70
- print(f"Fetched {len(questions_data)} questions.")
71
- except requests.exceptions.RequestException as e:
72
- print(f"Error fetching questions: {e}")
73
- return f"Error fetching questions: {e}", None
74
- except requests.exceptions.JSONDecodeError as e:
75
- print(f"Error decoding JSON response from questions endpoint: {e}")
76
- print(f"Response text: {response.text[:500]}")
77
- return f"Error decoding server response for questions: {e}", None
78
- except Exception as e:
79
- print(f"An unexpected error occurred fetching questions: {e}")
80
- return f"An unexpected error occurred fetching questions: {e}", None
81
-
82
- # 3. Run your Agent
83
- results_log = []
84
- answers_payload = []
85
- print(f"Running agent on {len(questions_data)} questions...")
86
- for item in questions_data:
87
- task_id = item.get("task_id")
88
- question_text = item.get("question")
89
- print(f"running on Question data {question_text}")
90
- if not task_id or question_text is None:
91
- print(f"Skipping item with missing task_id or question: {item}")
92
- continue
93
  try:
94
- submitted_answer = agent(question_text)
95
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
96
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
97
  except Exception as e:
98
- print(f"Error running agent on task {task_id}: {e}")
99
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
100
-
101
- if not answers_payload:
102
- print("Agent did not produce any answers to submit.")
103
- return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
104
-
105
- # 4. Prepare Submission
106
- submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
107
- status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
108
- print(status_update)
109
-
110
- if(mode == "test"):
111
- # 5a test
112
- question = "When was a picture of St. Thomas Aquinas first added to the wikipedia page on the principle of double effect?"
113
- graph = build_graph(provider="groq")
114
- messages = [HumanMessage(content=question)]
115
- print("message {messages}")
116
- messages = graph.invoke(
117
- input= {"messages": messages},
118
- config={"callbacks": [langfuse_handler]}
119
- )
120
- graph.get_graph().draw_mermaid_png()
121
-
122
- for m in messages["messages"]:
123
- m.pretty_print()
124
- print("m-Message{m}")
125
-
126
  else:
127
- # 5b. Submit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
129
  try:
130
  response = requests.post(submit_url, json=submission_data, timeout=60)
 
57
  # 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)
58
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
59
  print(agent_code)
60
+
61
+ if(mode != "live"):
62
+ # 5a test
63
+ question = "When was a picture of St. Thomas Aquinas first added to the wikipedia page on the principle of double effect?"
64
+ #graph = build_graph(provider="groq")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  try:
66
+ submitted_answer = agent(question)
67
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
68
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
69
  except Exception as e:
70
+ print(f"Error running agent on task {task_id}: {e}")
71
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  else:
73
+
74
+ # 2. Fetch Questions
75
+ print(f"Fetching questions from: {questions_url}")
76
+ try:
77
+ response = requests.get(questions_url, timeout=15)
78
+ response.raise_for_status()
79
+ questions_data = response.json()
80
+ if not questions_data:
81
+ print("Fetched questions list is empty.")
82
+ return "Fetched questions list is empty or invalid format.", None
83
+ print(f"Fetched {len(questions_data)} questions.")
84
+ except requests.exceptions.RequestException as e:
85
+ print(f"Error fetching questions: {e}")
86
+ return f"Error fetching questions: {e}", None
87
+ except requests.exceptions.JSONDecodeError as e:
88
+ print(f"Error decoding JSON response from questions endpoint: {e}")
89
+ print(f"Response text: {response.text[:500]}")
90
+ return f"Error decoding server response for questions: {e}", None
91
+ except Exception as e:
92
+ print(f"An unexpected error occurred fetching questions: {e}")
93
+ return f"An unexpected error occurred fetching questions: {e}", None
94
+
95
+ # 3. Run your Agent
96
+ results_log = []
97
+ answers_payload = []
98
+ print(f"Running agent on {len(questions_data)} questions...")
99
+ for item in questions_data:
100
+ task_id = item.get("task_id")
101
+ question_text = item.get("question")
102
+ print(f"running on Question data {question_text}")
103
+ if not task_id or question_text is None:
104
+ print(f"Skipping item with missing task_id or question: {item}")
105
+ continue
106
+ try:
107
+ submitted_answer = agent(question_text)
108
+ answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
109
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
110
+ except Exception as e:
111
+ print(f"Error running agent on task {task_id}: {e}")
112
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
113
+
114
+ if not answers_payload:
115
+ print("Agent did not produce any answers to submit.")
116
+ return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
117
+
118
+ # 4. Prepare Submission
119
+ submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
120
+ status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
121
+ print(status_update)
122
+
123
+ # 5. Submit
124
  print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
125
  try:
126
  response = requests.post(submit_url, json=submission_data, timeout=60)