Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
from agent import build_agent
|
| 7 |
from langchain_core.messages import AnyMessage, HumanMessage, AIMessage
|
|
|
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
@@ -19,9 +20,9 @@ class BasicAgent:
|
|
| 19 |
def __call__(self, question: str) -> str:
|
| 20 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 21 |
question = [HumanMessage(content=question)]
|
| 22 |
-
final_answer = self.agent.invoke({"
|
| 23 |
print(f"Agent returning fixed answer: {final_answer}")
|
| 24 |
-
return final_answer
|
| 25 |
|
| 26 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 27 |
"""
|
|
@@ -47,6 +48,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 47 |
agent = BasicAgent()
|
| 48 |
except Exception as e:
|
| 49 |
print(f"Error instantiating agent: {e}")
|
|
|
|
| 50 |
return f"Error initializing agent: {e}", None
|
| 51 |
# 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)
|
| 52 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
@@ -90,6 +92,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 90 |
except Exception as e:
|
| 91 |
print(f"Error running agent on task {task_id}: {e}")
|
| 92 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
|
|
|
| 93 |
|
| 94 |
if not answers_payload:
|
| 95 |
print("Agent did not produce any answers to submit.")
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from agent import build_agent
|
| 7 |
from langchain_core.messages import AnyMessage, HumanMessage, AIMessage
|
| 8 |
+
import traceback
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
|
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 22 |
question = [HumanMessage(content=question)]
|
| 23 |
+
final_answer = self.agent.invoke({"messages": question})
|
| 24 |
print(f"Agent returning fixed answer: {final_answer}")
|
| 25 |
+
return final_answer["messages"][-1].content
|
| 26 |
|
| 27 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 28 |
"""
|
|
|
|
| 48 |
agent = BasicAgent()
|
| 49 |
except Exception as e:
|
| 50 |
print(f"Error instantiating agent: {e}")
|
| 51 |
+
traceback.print_exc()
|
| 52 |
return f"Error initializing agent: {e}", None
|
| 53 |
# 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)
|
| 54 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
|
|
| 92 |
except Exception as e:
|
| 93 |
print(f"Error running agent on task {task_id}: {e}")
|
| 94 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 95 |
+
traceback.print_exc()
|
| 96 |
|
| 97 |
if not answers_payload:
|
| 98 |
print("Agent did not produce any answers to submit.")
|