FD900 commited on
Commit
c668f8c
·
verified ·
1 Parent(s): 4169046

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -76
app.py DELETED
@@ -1,76 +0,0 @@
1
- import gradio as gr
2
- import json
3
- import os
4
- import traceback
5
-
6
- from agent import answer_question
7
- from submit import submit_answers
8
- from tools.file_loader import read_pdf, read_csv, read_txt
9
-
10
- qa_data = []
11
- answers = []
12
-
13
- def run_agent():
14
- global qa_data, answers
15
- try:
16
- status_lines = []
17
-
18
- with open("data/metadata.jsonl", "r", encoding="utf-8") as f:
19
- lines = f.readlines()[:20]
20
- qa_data = [json.loads(line) for line in lines]
21
-
22
- answers = []
23
-
24
- for idx, q in enumerate(qa_data, start=1):
25
- task_id = q.get("task_id")
26
- question = q.get("question")
27
- file_text = None
28
-
29
- file_name = q.get("file_name", "")
30
- if file_name:
31
- file_path = os.path.join("data", file_name)
32
- try:
33
- if file_name.endswith(".pdf"):
34
- file_text = read_pdf(file_path)
35
- elif file_name.endswith(".csv"):
36
- file_text = read_csv(file_path)
37
- elif file_name.endswith(".txt"):
38
- file_text = read_txt(file_path)
39
- except Exception as e:
40
- status_lines.append(f"⚠️ Failed to read file {file_name}: {e}")
41
-
42
- response = answer_question(question, file_context=file_text, do_search=False)
43
- answers.append({"task_id": task_id, "submitted_answer": response})
44
- status_lines.append(f"✅ Q{idx}: Answered")
45
-
46
- return "🎯 Done.\n\n" + "\n".join(
47
- [f"✅ Q{idx+1} (ID {a['task_id']}): {a['submitted_answer']}" for idx, a in enumerate(answers)]
48
- )
49
-
50
- except Exception as e:
51
- return f"❌ Error:\n{traceback.format_exc()}"
52
-
53
- def handle_submit(username, code_link):
54
- try:
55
- result = submit_answers(username, code_link, answers)
56
- return result
57
- except Exception as e:
58
- return f"❌ Submission error:\n{traceback.format_exc()}"
59
-
60
- with gr.Blocks() as demo:
61
- gr.Markdown("# 🤖 GAIA Level 1 Agent (Local - Hugging Face CPU Inference)")
62
-
63
- with gr.Row():
64
- username = gr.Textbox(label="Your Hugging Face Username")
65
- code_link = gr.Textbox(label="Your Space Code Link (/tree/main)")
66
-
67
- status = gr.Textbox(label="Status", lines=15)
68
-
69
- run_btn = gr.Button("🧠 Run Agent")
70
- submit_btn = gr.Button("🚀 Submit Answers")
71
-
72
- run_btn.click(fn=run_agent, outputs=status)
73
- submit_btn.click(fn=handle_submit, inputs=[username, code_link], outputs=status)
74
-
75
- if __name__ == "__main__":
76
- demo.launch()