Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import pandas as pd
|
|
| 6 |
from src.agent import BasicAgent
|
| 7 |
from datasets import load_dataset
|
| 8 |
from huggingface_hub import snapshot_download
|
|
|
|
| 9 |
|
| 10 |
# (Keep Constants as is)
|
| 11 |
# --- Constants ---
|
|
@@ -71,12 +72,31 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 71 |
|
| 72 |
# Decide binary or text
|
| 73 |
if file_name.endswith((".txt", ".py", ".csv", ".json")):
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
if not task_id or question_text is None:
|
|
|
|
| 6 |
from src.agent import BasicAgent
|
| 7 |
from datasets import load_dataset
|
| 8 |
from huggingface_hub import snapshot_download
|
| 9 |
+
from docx import Document
|
| 10 |
|
| 11 |
# (Keep Constants as is)
|
| 12 |
# --- Constants ---
|
|
|
|
| 72 |
|
| 73 |
# Decide binary or text
|
| 74 |
if file_name.endswith((".txt", ".py", ".csv", ".json")):
|
| 75 |
+
try:
|
| 76 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
| 77 |
+
file_content = f.read()
|
| 78 |
+
print(f"File Content is {file_content}, {file_path}")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
print(f"Error reading text file {file_path}: {e}")
|
| 81 |
+
file_content = None
|
| 82 |
+
elif file_name.endswith(".docx"):
|
| 83 |
+
try:
|
| 84 |
+
doc = Document(file_path)
|
| 85 |
+
file_content = "\n".join([p.text for p in doc.paragraphs])
|
| 86 |
+
print(f"Docx content loaded, {file_path}")
|
| 87 |
+
except Exception as e:
|
| 88 |
+
print(f"Error reading docx file {file_path}: {e}")
|
| 89 |
+
file_content = None
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
else: # binary files like images, audio, video
|
| 93 |
+
try:
|
| 94 |
+
with open(file_path, "rb") as f:
|
| 95 |
+
file_content = f.read()
|
| 96 |
+
print(f"Binary file loaded, {file_path}")
|
| 97 |
+
except Exception as e:
|
| 98 |
+
print(f"Error reading binary file {file_path}: {e}")
|
| 99 |
+
file_content = None
|
| 100 |
|
| 101 |
|
| 102 |
if not task_id or question_text is None:
|