Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from api import get_all_questions, submit_answers, get_file | |
| from agent import answer_question | |
| from tools.file_loader import read_pdf, read_csv, read_txt | |
| qa_data = [] | |
| answers = [] | |
| def run_agent(): | |
| global qa_data, answers | |
| qa_data = get_all_questions() | |
| answers = [] | |
| for q in qa_data: | |
| task_id = q['task_id'] | |
| question = q['question'] | |
| file_text = None | |
| if q.get("files"): | |
| for fname in q["files"]: | |
| raw = get_file(task_id, fname) | |
| if fname.endswith(".pdf"): | |
| file_text = read_pdf(raw) | |
| elif fname.endswith(".csv"): | |
| file_text = read_csv(raw) | |
| elif fname.endswith(".txt"): | |
| file_text = read_txt(raw) | |
| break | |
| response = answer_question(question, file_context=file_text, do_search=True) | |
| answers.append({"task_id": task_id, "submitted_answer": response}) | |
| return f"β Agent answered {len(answers)} questions. Ready to submit!" | |
| def handle_submit(username, code_link): | |
| return submit_answers(username, code_link, answers) | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π€ GAIA Level 1 Agent") | |
| with gr.Row(): | |
| username = gr.Textbox(label="Hugging Face Username") | |
| code_link = gr.Textbox(label="Space Code URL (/tree/main)") | |
| status = gr.Textbox(label="Status", lines=4) | |
| 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() |