Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import traceback
|
|
| 5 |
|
| 6 |
from agent import answer_question
|
| 7 |
from submit import submit_answers
|
|
|
|
| 8 |
|
| 9 |
qa_data = []
|
| 10 |
answers = []
|
|
@@ -21,14 +22,24 @@ def run_agent():
|
|
| 21 |
answers = []
|
| 22 |
|
| 23 |
for idx, q in enumerate(qa_data, start=1):
|
| 24 |
-
task_id = q.get("task_id"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
# Construct full path and ensure required fields
|
| 28 |
-
q["question"] = q.get("question", "")
|
| 29 |
-
q["file_path"] = os.path.join("data", file_name) if file_name else ""
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
answers.append({"task_id": task_id, "submitted_answer": response})
|
| 33 |
status_lines.append(f"✅ Q{idx}: Answered")
|
| 34 |
|
|
@@ -47,7 +58,7 @@ def handle_submit(username, code_link):
|
|
| 47 |
return f"❌ Submission error:\n{traceback.format_exc()}"
|
| 48 |
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
-
gr.Markdown("# 🤖 GAIA Level 1 Agent (Local -
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
username = gr.Textbox(label="Your Hugging Face Username")
|
|
|
|
| 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 = []
|
|
|
|
| 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 |
|
|
|
|
| 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")
|