Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import json
|
|
|
|
|
|
|
|
|
|
| 3 |
from agent import answer_question
|
| 4 |
from submit import submit_answers
|
| 5 |
from tools.file_loader import read_pdf, read_csv, read_txt
|
| 6 |
-
import os
|
| 7 |
-
import traceback
|
| 8 |
|
| 9 |
qa_data = []
|
| 10 |
answers = []
|
|
@@ -13,6 +14,7 @@ def run_agent():
|
|
| 13 |
global qa_data, answers
|
| 14 |
try:
|
| 15 |
status_lines = []
|
|
|
|
| 16 |
with open("data/metadata.jsonl", "r", encoding="utf-8") as f:
|
| 17 |
lines = f.readlines()[:20]
|
| 18 |
qa_data = [json.loads(line) for line in lines]
|
|
@@ -28,19 +30,19 @@ def run_agent():
|
|
| 28 |
if file_name:
|
| 29 |
file_path = os.path.join("data", file_name)
|
| 30 |
try:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
file_text = read_pdf(f.read())
|
| 34 |
-
|
| 35 |
-
with open(file_path, "rb") as f:
|
| 36 |
file_text = read_csv(f.read())
|
| 37 |
-
|
| 38 |
-
with open(file_path, "rb") as f:
|
| 39 |
file_text = read_txt(f.read())
|
| 40 |
except Exception as e:
|
| 41 |
status_lines.append(f"⚠️ Failed to read file {file_name}: {e}")
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
answers.append({"task_id": task_id, "submitted_answer": response})
|
| 45 |
status_lines.append(f"✅ Q{idx}: Answered")
|
| 46 |
|
|
|
|
| 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 = []
|
|
|
|
| 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]
|
|
|
|
| 30 |
if file_name:
|
| 31 |
file_path = os.path.join("data", file_name)
|
| 32 |
try:
|
| 33 |
+
with open(file_path, "rb") as f:
|
| 34 |
+
if file_name.endswith(".pdf"):
|
| 35 |
file_text = read_pdf(f.read())
|
| 36 |
+
elif file_name.endswith(".csv"):
|
|
|
|
| 37 |
file_text = read_csv(f.read())
|
| 38 |
+
elif file_name.endswith(".txt"):
|
|
|
|
| 39 |
file_text = read_txt(f.read())
|
| 40 |
except Exception as e:
|
| 41 |
status_lines.append(f"⚠️ Failed to read file {file_name}: {e}")
|
| 42 |
|
| 43 |
+
# Pass file path to agent
|
| 44 |
+
q["file_path"] = os.path.join("data", file_name) if file_name else ""
|
| 45 |
+
response = answer_question(q)
|
| 46 |
answers.append({"task_id": task_id, "submitted_answer": response})
|
| 47 |
status_lines.append(f"✅ Q{idx}: Answered")
|
| 48 |
|