FD900's picture
Update app.py
d6ca7ae verified
raw
history blame
1.45 kB
import gradio as gr
import json
import os
import requests
from .agent import solve_task, load_tasks
from .mistral_hf_wrapper import MistralInference
# Load from environment variables
API_URL = os.getenv("HF_MISTRAL_ENDPOINT")
API_TOKEN = os.getenv("HF_TOKEN")
USERNAME = os.getenv("HF_USERNAME")
CODE_LINK = os.getenv("HF_CODE_LINK")
# Launches agent to solve all tasks and submits to GAIA
def run_and_submit_all():
model = MistralInference(api_url=API_URL, api_token=API_TOKEN)
tasks = load_tasks()
answers = []
for task in tasks:
try:
result = solve_task(task, model)
answers.append(result)
except Exception as e:
answers.append({
"task_id": task.get("question_id", "unknown"),
"submitted_answer": f"ERROR: {str(e)}"
})
# Submit results to GAIA benchmark API
res = requests.post(
"https://agents-course-unit4-scoring.hf.space/submit",
headers={"Content-Type": "application/json"},
json={
"username": USERNAME,
"agent_code": CODE_LINK,
"answers": answers
},
)
if res.ok:
return json.dumps(res.json(), indent=2)
else:
return f"Error submitting: {res.status_code} - {res.text}"
# Gradio interface
gr.Interface(
fn=run_and_submit_all,
inputs=[],
outputs="textbox",
title="GAIA Benchmark Agent Submission"
).launch()