Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import json | |
| import os | |
| import traceback | |
| from agent import answer_question | |
| from submit import submit_answers | |
| qa_data = [] | |
| answers = [] | |
| def run_agent(): | |
| global qa_data, answers | |
| try: | |
| status_lines = [] | |
| with open("data/metadata.jsonl", "r", encoding="utf-8") as f: | |
| lines = f.readlines()[:20] | |
| qa_data = [json.loads(line) for line in lines] | |
| answers = [] | |
| for idx, q in enumerate(qa_data, start=1): | |
| task_id = q.get("task_id", "") | |
| file_name = q.get("file_name", "") | |
| # Construct full path and ensure required fields | |
| q["question"] = q.get("question", "") | |
| q["file_path"] = os.path.join("data", file_name) if file_name else "" | |
| response = answer_question(q) | |
| answers.append({"task_id": task_id, "submitted_answer": response}) | |
| status_lines.append(f"β Q{idx}: Answered") | |
| return "π― Done.\n\n" + "\n".join( | |
| [f"β Q{idx+1} (ID {a['task_id']}): {a['submitted_answer']}" for idx, a in enumerate(answers)] | |
| ) | |
| except Exception as e: | |
| return f"β Error:\n{traceback.format_exc()}" | |
| def handle_submit(username, code_link): | |
| try: | |
| result = submit_answers(username, code_link, answers) | |
| return result | |
| except Exception as e: | |
| return f"β Submission error:\n{traceback.format_exc()}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π€ GAIA Level 1 Agent (Local - Validation Set)") | |
| with gr.Row(): | |
| username = gr.Textbox(label="Your Hugging Face Username") | |
| code_link = gr.Textbox(label="Your Space Code Link (/tree/main)") | |
| status = gr.Textbox(label="Status", lines=15) | |
| run_btn = gr.Button("π§ Run Agent") | |
| submit_btn = gr.Button("π Submit Answers") | |
| run_btn.click(fn=run_agent, outputs=status) | |
| submit_btn.click(fn=handle_submit, inputs=[username, code_link], outputs=status) | |
| if __name__ == "__main__": | |
| demo.launch() |