Update app.py
Browse files
app.py
CHANGED
|
@@ -3,14 +3,17 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
from final_agent import FinalAgent
|
|
|
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
-
# -----
|
| 14 |
|
| 15 |
|
| 16 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
@@ -69,17 +72,28 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 69 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 70 |
for item in questions_data:
|
| 71 |
task_id = item.get("task_id")
|
| 72 |
-
|
| 73 |
-
if not task_id or
|
| 74 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 75 |
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
try:
|
| 77 |
-
submitted_answer = agent(
|
| 78 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 79 |
-
results_log.append({"Task ID": task_id, "Question":
|
| 80 |
except Exception as e:
|
| 81 |
print(f"Error running agent on task {task_id}: {e}")
|
| 82 |
-
results_log.append({"Task ID": task_id, "Question":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
if not answers_payload:
|
| 85 |
print("Agent did not produce any answers to submit.")
|
|
@@ -186,3 +200,4 @@ if __name__ == "__main__":
|
|
| 186 |
|
| 187 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 188 |
demo.launch(debug=True, share=False)
|
|
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
import tempfile
|
| 7 |
+
from pathlib import Path
|
| 8 |
from final_agent import FinalAgent
|
| 9 |
+
from utils import process_file_for_task_v2
|
| 10 |
|
| 11 |
# (Keep Constants as is)
|
| 12 |
# --- Constants ---
|
| 13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
|
| 15 |
# --- Basic Agent Definition ---
|
| 16 |
+
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 17 |
|
| 18 |
|
| 19 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
| 72 |
print(f"Running agent on {len(questions_data)} questions...")
|
| 73 |
for item in questions_data:
|
| 74 |
task_id = item.get("task_id")
|
| 75 |
+
original_question_text = item.get("question")
|
| 76 |
+
if not task_id or original_question_text is None:
|
| 77 |
print(f"Skipping item with missing task_id or question: {item}")
|
| 78 |
continue
|
| 79 |
+
question_text_for_agent, downloaded_file_path = process_file_for_task_v2(task_id, original_question_text, DEFAULT_API_URL)
|
| 80 |
+
|
| 81 |
+
local_file_to_clean = downloaded_file_path # Use the returned path for cleanup
|
| 82 |
+
|
| 83 |
try:
|
| 84 |
+
submitted_answer = agent(question_text_for_agent, task_id=task_id)
|
| 85 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 86 |
+
results_log.append({"Task ID": task_id, "Question": original_question_text, "Processed Question": question_text_for_agent, "Submitted Answer": submitted_answer})
|
| 87 |
except Exception as e:
|
| 88 |
print(f"Error running agent on task {task_id}: {e}")
|
| 89 |
+
results_log.append({"Task ID": task_id, "Question": original_question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 90 |
+
finally:
|
| 91 |
+
if local_file_to_clean and local_file_to_clean.exists():
|
| 92 |
+
try:
|
| 93 |
+
local_file_to_clean.unlink()
|
| 94 |
+
print(f"Cleaned up temporary file: {local_file_to_clean}")
|
| 95 |
+
except OSError as e_clean:
|
| 96 |
+
print(f"Error cleaning up temp file {local_file_to_clean}: {e_clean}")
|
| 97 |
|
| 98 |
if not answers_payload:
|
| 99 |
print("Agent did not produce any answers to submit.")
|
|
|
|
| 200 |
|
| 201 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 202 |
demo.launch(debug=True, share=False)
|
| 203 |
+
|