FD900 commited on
Commit
da279f9
·
verified ·
1 Parent(s): c0d60cf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from api import get_all_questions, submit_answers, get_file
3
+ from agent import answer_question
4
+ from tools.file_loader import read_pdf, read_csv, read_txt
5
+
6
+ qa_data = []
7
+ answers = []
8
+
9
+ def run_agent():
10
+ global qa_data, answers
11
+ qa_data = get_all_questions()
12
+ answers = []
13
+ for q in qa_data:
14
+ task_id = q['task_id']
15
+ question = q['question']
16
+ file_text = None
17
+ if q.get("files"):
18
+ for fname in q["files"]:
19
+ raw = get_file(task_id, fname)
20
+ if fname.endswith(".pdf"):
21
+ file_text = read_pdf(raw)
22
+ elif fname.endswith(".csv"):
23
+ file_text = read_csv(raw)
24
+ elif fname.endswith(".txt"):
25
+ file_text = read_txt(raw)
26
+ break
27
+
28
+ response = answer_question(question, file_context=file_text, do_search=True)
29
+ answers.append({"task_id": task_id, "submitted_answer": response})
30
+ return f"✅ Agent answered {len(answers)} questions. Ready to submit!"
31
+
32
+ def handle_submit(username, code_link):
33
+ return submit_answers(username, code_link, answers)
34
+
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# 🤖 GAIA Level 1 Agent")
37
+
38
+ with gr.Row():
39
+ username = gr.Textbox(label="Hugging Face Username")
40
+ code_link = gr.Textbox(label="Space Code URL (/tree/main)")
41
+
42
+ status = gr.Textbox(label="Status", lines=4)
43
+
44
+ run_btn = gr.Button("🔍 Run Agent")
45
+ submit_btn = gr.Button("📤 Submit Answers")
46
+
47
+ run_btn.click(fn=run_agent, outputs=status)
48
+ submit_btn.click(fn=handle_submit, inputs=[username, code_link], outputs=status)
49
+
50
+ if __name__ == "__main__":
51
+ demo.launch()