FD900's picture
Update app.py
290dcc5 verified
raw
history blame
1.67 kB
import gradio as gr
import json
import os
import requests
from agent import solve_task, load_tasks
from mistral_hf_wrapper import MistralInference
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")
def run_and_submit_all():
model = MistralInference(api_url=API_URL, api_token=API_TOKEN)
tasks = load_tasks()
if not tasks:
return "No tasks loaded from metadata.jsonl. Make sure the file exists and is valid."
answers = []
for task in tasks:
try:
result = solve_task(task, model)
if not result.get("submitted_answer"): # Check empty responses
result["submitted_answer"] = "ERROR: Empty model response"
answers.append(result)
except Exception as e:
answers.append({
"question_id": task.get("question_id", "UNKNOWN"),
"submitted_answer": f"ERROR: {str(e)}"
})
# Debug
if not answers:
return " No answers generated. Check model response."
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)
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()