Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from agent import GaiaAgent
|
|
| 6 |
|
| 7 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 8 |
|
| 9 |
-
agent = GaiaAgent()
|
| 10 |
|
| 11 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 12 |
space_id = os.getenv("SPACE_ID")
|
|
@@ -23,7 +22,13 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 23 |
submit_url = f"{api_url}/submit"
|
| 24 |
|
| 25 |
try:
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
response = requests.get(questions_url, timeout=15)
|
| 28 |
response.raise_for_status()
|
| 29 |
questions_data = response.json()
|
|
@@ -41,9 +46,14 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 41 |
continue
|
| 42 |
try:
|
| 43 |
final_answer, trace = agent(question_text)
|
| 44 |
-
|
| 45 |
-
print(
|
| 46 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
answers_payload.append({
|
| 49 |
"task_id": task_id,
|
|
@@ -74,39 +84,25 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 74 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 75 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 76 |
)
|
| 77 |
-
|
|
|
|
| 78 |
except Exception as e:
|
| 79 |
return f"Submission Failed: {e}", pd.DataFrame(results_log)
|
| 80 |
|
| 81 |
-
def evaluate(question, files):
|
| 82 |
-
uploaded_files = {}
|
| 83 |
-
if files:
|
| 84 |
-
for file in files:
|
| 85 |
-
file_path = file.name
|
| 86 |
-
file.save(file_path)
|
| 87 |
-
uploaded_files[file.name] = file_path
|
| 88 |
-
|
| 89 |
-
prediction, reasoning = agent(question, uploaded_files)
|
| 90 |
-
return prediction, reasoning
|
| 91 |
|
| 92 |
with gr.Blocks() as demo:
|
| 93 |
-
gr.Markdown("# GAIA Agent Interface")
|
| 94 |
-
gr.Markdown("
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
files = gr.File(label="Optional files (mp3, wav, xlsx)", file_types=['.mp3', '.wav', '.xlsx'], type="filepath", file_count="multiple")
|
| 106 |
-
submit = gr.Button("Run Agent")
|
| 107 |
-
answer = gr.Textbox(label="Answer")
|
| 108 |
-
reasoning = gr.Textbox(label="Reasoning Trace")
|
| 109 |
-
submit.click(fn=evaluate, inputs=[question, files], outputs=[answer, reasoning])
|
| 110 |
|
| 111 |
if __name__ == "__main__":
|
| 112 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
|
@@ -124,7 +120,7 @@ if __name__ == "__main__":
|
|
| 124 |
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
| 125 |
print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
|
| 126 |
else:
|
| 127 |
-
print("ℹ️ SPACE_ID environment variable not found (running locally?).")
|
| 128 |
|
| 129 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 130 |
|
|
|
|
| 6 |
|
| 7 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 11 |
space_id = os.getenv("SPACE_ID")
|
|
|
|
| 22 |
submit_url = f"{api_url}/submit"
|
| 23 |
|
| 24 |
try:
|
| 25 |
+
agent = GaiaAgent()
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error initializing agent: {e}", None
|
| 28 |
+
|
| 29 |
+
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
response = requests.get(questions_url, timeout=15)
|
| 33 |
response.raise_for_status()
|
| 34 |
questions_data = response.json()
|
|
|
|
| 46 |
continue
|
| 47 |
try:
|
| 48 |
final_answer, trace = agent(question_text)
|
| 49 |
+
|
| 50 |
+
print("\n--- QUESTION ---")
|
| 51 |
+
print(f"Task ID: {task_id}")
|
| 52 |
+
print(f"Question: {question_text}")
|
| 53 |
+
print("\n--- REASONING TRACE ---")
|
| 54 |
+
print(trace)
|
| 55 |
+
print("\n--- FINAL ANSWER (SUBMITTED) ---")
|
| 56 |
+
print(final_answer)
|
| 57 |
|
| 58 |
answers_payload.append({
|
| 59 |
"task_id": task_id,
|
|
|
|
| 84 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 85 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 86 |
)
|
| 87 |
+
results_df = pd.DataFrame(results_log)
|
| 88 |
+
return final_status, results_df
|
| 89 |
except Exception as e:
|
| 90 |
return f"Submission Failed: {e}", pd.DataFrame(results_log)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
with gr.Blocks() as demo:
|
| 94 |
+
gr.Markdown("# GAIA Agent Submission Interface")
|
| 95 |
+
gr.Markdown("""
|
| 96 |
+
Logga in och kör agenten.\n
|
| 97 |
+
Du behöver INTE en OpenAI API-nyckel längre. Agenten kör en lokal modell.
|
| 98 |
+
""")
|
| 99 |
+
gr.LoginButton()
|
| 100 |
+
|
| 101 |
+
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 102 |
+
status_output = gr.Textbox(label="Submission Result")
|
| 103 |
+
results_table = gr.DataFrame(label="Answers")
|
| 104 |
+
|
| 105 |
+
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
|
|
|
| 120 |
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
| 121 |
print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")
|
| 122 |
else:
|
| 123 |
+
print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")
|
| 124 |
|
| 125 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 126 |
|