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