FD900 commited on
Commit
c7945b3
·
verified ·
1 Parent(s): a1a42c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
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
- if file_name.endswith(".pdf"):
32
- with open(file_path, "rb") as f:
33
  file_text = read_pdf(f.read())
34
- elif file_name.endswith(".csv"):
35
- with open(file_path, "rb") as f:
36
  file_text = read_csv(f.read())
37
- elif file_name.endswith(".txt"):
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
- response = answer_question(question, file_context=file_text or "", do_search=False)
 
 
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