Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,10 +29,25 @@ class BasicAgent:
|
|
| 29 |
provider="auto",
|
| 30 |
max_iterations=10
|
| 31 |
)
|
| 32 |
-
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
| 37 |
|
| 38 |
async def run(self, question: str) -> str:
|
|
@@ -66,11 +81,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 66 |
submit_url = f"{api_url}/submit"
|
| 67 |
|
| 68 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
#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)
|
| 75 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 76 |
print(agent_code)
|
|
@@ -121,32 +136,20 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 121 |
#3A
|
| 122 |
|
| 123 |
async def run_all_questions(questions_data):
|
| 124 |
-
try:
|
| 125 |
-
agent = BasicAgent()
|
| 126 |
-
except Exception as e:
|
| 127 |
-
print(f"Error instantiating agent: {e}")
|
| 128 |
-
return f"Error initializing agent: {e}", None
|
| 129 |
-
question_text = questions_data[0].get("question")
|
| 130 |
-
task_id = questions_data[0].get("task_id")
|
| 131 |
-
print(f"Processing my question 0 : : : : : : :")
|
| 132 |
-
answer = await agent.run(question_text)
|
| 133 |
-
print(f"Answered Task {task_id}: {answer[:50]}...")
|
| 134 |
answers_payload = []
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
# answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
|
| 149 |
-
# print(f"Error on Task {task_id}: {e}")
|
| 150 |
return answers_payload
|
| 151 |
|
| 152 |
answers_payload = asyncio.run(run_all_questions(questions_data))
|
|
|
|
| 29 |
provider="auto",
|
| 30 |
max_iterations=10
|
| 31 |
)
|
| 32 |
+
# self.agent = AgentWorkflow.from_tools_or_functions(
|
| 33 |
+
# [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool,
|
| 34 |
+
# round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
|
| 35 |
+
# llm=self.llm
|
| 36 |
+
# )
|
| 37 |
+
|
| 38 |
+
self.tools = [
|
| 39 |
+
wikipedia_search_tool,
|
| 40 |
+
youtube_transcript_tool,
|
| 41 |
+
youtube_transcript_snippet_tool,
|
| 42 |
+
round_to_two_decimals_tool,
|
| 43 |
+
text_inverter_tool,
|
| 44 |
+
google_web_search_tool
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
self.agent = ReActAgent.from_tools(
|
| 48 |
+
tools=self.tools,
|
| 49 |
+
llm=self.llm,
|
| 50 |
+
verbose=True
|
| 51 |
)
|
| 52 |
|
| 53 |
async def run(self, question: str) -> str:
|
|
|
|
| 81 |
submit_url = f"{api_url}/submit"
|
| 82 |
|
| 83 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 84 |
+
try:
|
| 85 |
+
agent = BasicAgent()
|
| 86 |
+
except Exception as e:
|
| 87 |
+
print(f"Error instantiating agent: {e}")
|
| 88 |
+
return f"Error initializing agent: {e}", None
|
| 89 |
#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)
|
| 90 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 91 |
print(agent_code)
|
|
|
|
| 136 |
#3A
|
| 137 |
|
| 138 |
async def run_all_questions(questions_data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
answers_payload = []
|
| 140 |
+
for item in questions_data:
|
| 141 |
+
task_id = item.get("task_id")
|
| 142 |
+
question_text = item.get("question")
|
| 143 |
+
if not task_id or question_text is None:
|
| 144 |
+
print(f"Skipping item with missing task_id or question: {item}")
|
| 145 |
+
continue
|
| 146 |
+
try:
|
| 147 |
+
answer = await agent.run(question_text) # await coroutine
|
| 148 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": answer})
|
| 149 |
+
print(f"Answered Task {task_id}: {answer[:50]}...")
|
| 150 |
+
except Exception as e:
|
| 151 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
|
| 152 |
+
print(f"Error on Task {task_id}: {e}")
|
|
|
|
|
|
|
| 153 |
return answers_payload
|
| 154 |
|
| 155 |
answers_payload = asyncio.run(run_all_questions(questions_data))
|