Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines34567899 unmodified lines192021212223242513 unmodified lines3940414243444533 unmodified lines7980818283848586878889909192939495969798991001011021031041051061071081091101111121132 unmodified linesimport requestsimport inspectimport pandas as pd
from my_agent import agent
# (Keep Constants as is)9 unmodified lines print(f"Agent received question (first 50 chars): {question[:50]}...") agent_response = agent.run(question) print(f"Agent returning fixed answer: {agent_response}") return agent_response return agent_response.strip()
def run_and_submit_all( profile: gr.OAuthProfile | None): """13 unmodified lines api_url = DEFAULT_API_URL questions_url = f"{api_url}/questions" submit_url = f"{api_url}/submit" file_url = f"{api_url}/files"
# 1. Instantiate Agent ( modify this part to create your agent) try:33 unmodified lines for item in questions_data: task_id = item.get("task_id") question_text = item.get("question") file_name = item.get("file_name")
if file_name: # Ensure the documents directory exists documents_dir = "documents" os.makedirs(documents_dir, exist_ok=True)
# Clear the documents directory for file in os.listdir(documents_dir): file_path = os.path.join(documents_dir, file) if os.path.isfile(file_path): os.remove(file_path)
# Download the file file_download_url = f"{file_url}/{task_id}" try: file_response = requests.get(file_download_url, timeout=15) file_response.raise_for_status() file_path = os.path.join(documents_dir, file_name) with open(file_path, "wb") as f: f.write(file_response.content) print(f"File downloaded and saved to: {file_path}") except requests.exceptions.RequestException as e: print(f"Error downloading file for task {task_id}: {e}") continue
question_text += f" (File Name: {file_name})"
if not task_id or question_text is None: print(f"Skipping item with missing task_id or question: {item}") continueapp.py+32-1