Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
from langchain_core.messages import HumanMessage
|
| 5 |
from graph_builder import build_graph
|
| 6 |
from api_client import fetch_questions, submit_answers
|
|
@@ -15,45 +16,64 @@ class GaiaAgent:
|
|
| 15 |
return result_state["final_answer"]
|
| 16 |
|
| 17 |
def run_and_submit_all(profile):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
question = item["question"]
|
| 33 |
-
answer = agent(question)
|
| 34 |
-
answers_payload.append({"task_id": task_id, "submitted_answer": answer})
|
| 35 |
-
results_log.append({"Task ID": task_id, "Question": question, "Submitted Answer": answer})
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
-
gr.Markdown("# GAIA LangGraph Agent")
|
| 43 |
-
gr.Markdown("Log in and run your agent to evaluate on GAIA benchmark.")
|
| 44 |
|
| 45 |
login_button = gr.LoginButton()
|
| 46 |
-
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 47 |
-
status_output = gr.Textbox(label="Run Status", lines=
|
| 48 |
results_table = gr.DataFrame(label="Results")
|
| 49 |
|
| 50 |
run_button.click(
|
| 51 |
fn=run_and_submit_all,
|
| 52 |
-
inputs=[login_button],
|
| 53 |
outputs=[status_output, results_table]
|
| 54 |
)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
if __name__ == "__main__":
|
| 59 |
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
+
import traceback
|
| 5 |
from langchain_core.messages import HumanMessage
|
| 6 |
from graph_builder import build_graph
|
| 7 |
from api_client import fetch_questions, submit_answers
|
|
|
|
| 16 |
return result_state["final_answer"]
|
| 17 |
|
| 18 |
def run_and_submit_all(profile):
|
| 19 |
+
try:
|
| 20 |
+
space_id = os.getenv("SPACE_ID")
|
| 21 |
+
username = profile.username if profile else None
|
| 22 |
+
if not username:
|
| 23 |
+
return "❌ Please log in to Hugging Face.", None
|
| 24 |
|
| 25 |
+
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 26 |
+
agent = GaiaAgent()
|
| 27 |
|
| 28 |
+
questions_data = fetch_questions()
|
| 29 |
+
if not questions_data:
|
| 30 |
+
return "❌ No questions retrieved from GAIA API.", None
|
| 31 |
|
| 32 |
+
answers_payload = []
|
| 33 |
+
results_log = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
for item in questions_data:
|
| 36 |
+
task_id = item["task_id"]
|
| 37 |
+
question = item["question"]
|
| 38 |
+
answer = agent(question)
|
| 39 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": answer})
|
| 40 |
+
results_log.append({
|
| 41 |
+
"Task ID": task_id,
|
| 42 |
+
"Question": question,
|
| 43 |
+
"Submitted Answer": answer
|
| 44 |
+
})
|
| 45 |
+
|
| 46 |
+
result = submit_answers(username, agent_code, answers_payload)
|
| 47 |
+
final_status = (
|
| 48 |
+
f"✅ Submission Successful!\n"
|
| 49 |
+
f"User: {result.get('username')}\n"
|
| 50 |
+
f"Score: {result.get('score')}%\n"
|
| 51 |
+
f"Correct: {result.get('correct_count')}/{result.get('total_attempted')}\n"
|
| 52 |
+
f"Message: {result.get('message', '')}"
|
| 53 |
+
)
|
| 54 |
+
return final_status, pd.DataFrame(results_log)
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
error_message = (
|
| 58 |
+
f"❌ An error occurred:\n{str(e)}\n\n"
|
| 59 |
+
f"Traceback:\n{traceback.format_exc()}"
|
| 60 |
+
)
|
| 61 |
+
return error_message, None
|
| 62 |
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
+
gr.Markdown("# 🤖 GAIA LangGraph Agent")
|
| 65 |
+
gr.Markdown("Log in and run your agent to evaluate on the GAIA benchmark.")
|
| 66 |
|
| 67 |
login_button = gr.LoginButton()
|
| 68 |
+
run_button = gr.Button("🚀 Run Evaluation & Submit All Answers")
|
| 69 |
+
status_output = gr.Textbox(label="Run Status", lines=10)
|
| 70 |
results_table = gr.DataFrame(label="Results")
|
| 71 |
|
| 72 |
run_button.click(
|
| 73 |
fn=run_and_submit_all,
|
| 74 |
+
inputs=[login_button], # wire login profile as input
|
| 75 |
outputs=[status_output, results_table]
|
| 76 |
)
|
| 77 |
|
|
|
|
|
|
|
| 78 |
if __name__ == "__main__":
|
| 79 |
demo.launch()
|