File size: 1,921 Bytes
8ac5ef4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
from agent.local_llm import LocalLLM
from agent.tools import gaia_tools
from llama_index.core.agent import ReActAgent
from utils.gaia_api import GaiaAPI

# Initialize components
llm = LocalLLM()
agent = ReActAgent.from_tools(gaia_tools, llm=llm.pipeline)

def process_question(question_text: str) -> str:
    """Process GAIA question through agent"""
    try:
        response = agent.query(question_text)
        return str(response)
    except Exception as e:
        return f"Error: {str(e)}"

def submit_to_gaia(username: str, code_url: str) -> str:
    """Submit all answers to GAIA"""
    try:
        questions = GaiaAPI.get_questions()
        answers = []
        for q in questions:
            answer = process_question(q['question'])
            answers.append({
                "task_id": q['task_id'],
                "submitted_answer": answer
            })
        result = GaiaAPI.submit_answers(username, code_url, answers)
        return f"Submitted! Score: {result.get('score', 'N/A')}"
    except Exception as e:
        return f"Submission failed: {str(e)}"

with gr.Blocks() as demo:
    gr.Markdown("# GAIA Benchmark Agent")
    
    with gr.Tab("Question Processing"):
        question_input = gr.Textbox(label="Enter GAIA Question")
        answer_output = gr.Textbox(label="Agent Answer")
        process_btn = gr.Button("Process Question")
        process_btn.click(process_question, inputs=question_input, outputs=answer_output)
    
    with gr.Tab("GAIA Submission"):
        username_input = gr.Textbox(label="HF Username")
        code_url_input = gr.Textbox(label="Space Code URL")
        submit_btn = gr.Button("Submit to GAIA")
        submission_output = gr.Textbox(label="Submission Result")
        submit_btn.click(
            submit_to_gaia,
            inputs=[username_input, code_url_input],
            outputs=submission_output
        )

demo.launch()