Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
from my_agent import agent
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
|
@@ -18,7 +19,7 @@ class BasicAgent:
|
|
| 18 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 19 |
agent_response = agent.run(question)
|
| 20 |
print(f"Agent returning fixed answer: {agent_response}")
|
| 21 |
-
return agent_response
|
| 22 |
|
| 23 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 24 |
"""
|
|
@@ -38,6 +39,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 38 |
api_url = DEFAULT_API_URL
|
| 39 |
questions_url = f"{api_url}/questions"
|
| 40 |
submit_url = f"{api_url}/submit"
|
|
|
|
| 41 |
|
| 42 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 43 |
try:
|
|
@@ -77,6 +79,35 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 77 |
for item in questions_data:
|
| 78 |
task_id = item.get("task_id")
|
| 79 |
question_text = item.get("question")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
if not task_id or question_text is None:
|
| 81 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 82 |
continue
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
|
| 7 |
from my_agent import agent
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
|
|
|
| 19 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 20 |
agent_response = agent.run(question)
|
| 21 |
print(f"Agent returning fixed answer: {agent_response}")
|
| 22 |
+
return agent_response.strip()
|
| 23 |
|
| 24 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 25 |
"""
|
|
|
|
| 39 |
api_url = DEFAULT_API_URL
|
| 40 |
questions_url = f"{api_url}/questions"
|
| 41 |
submit_url = f"{api_url}/submit"
|
| 42 |
+
file_url = f"{api_url}/files"
|
| 43 |
|
| 44 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 45 |
try:
|
|
|
|
| 79 |
for item in questions_data:
|
| 80 |
task_id = item.get("task_id")
|
| 81 |
question_text = item.get("question")
|
| 82 |
+
file_name = item.get("file_name")
|
| 83 |
+
|
| 84 |
+
if file_name:
|
| 85 |
+
# Ensure the documents directory exists
|
| 86 |
+
documents_dir = "documents"
|
| 87 |
+
os.makedirs(documents_dir, exist_ok=True)
|
| 88 |
+
|
| 89 |
+
# Clear the documents directory
|
| 90 |
+
for file in os.listdir(documents_dir):
|
| 91 |
+
file_path = os.path.join(documents_dir, file)
|
| 92 |
+
if os.path.isfile(file_path):
|
| 93 |
+
os.remove(file_path)
|
| 94 |
+
|
| 95 |
+
# Download the file
|
| 96 |
+
file_download_url = f"{file_url}/{task_id}"
|
| 97 |
+
try:
|
| 98 |
+
file_response = requests.get(file_download_url, timeout=15)
|
| 99 |
+
file_response.raise_for_status()
|
| 100 |
+
file_path = os.path.join(documents_dir, file_name)
|
| 101 |
+
with open(file_path, "wb") as f:
|
| 102 |
+
f.write(file_response.content)
|
| 103 |
+
print(f"File downloaded and saved to: {file_path}")
|
| 104 |
+
except requests.exceptions.RequestException as e:
|
| 105 |
+
print(f"Error downloading file for task {task_id}: {e}")
|
| 106 |
+
continue
|
| 107 |
+
|
| 108 |
+
question_text += f" (File Name: {file_name})"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
if not task_id or question_text is None:
|
| 112 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 113 |
continue
|