Update app.py
Browse files
app.py
CHANGED
@@ -42,10 +42,10 @@ def clean_response(text: str) -> str:
|
|
42 |
def estimate_tokens(text: str) -> int:
|
43 |
return len(text) // 3.5 + 1
|
44 |
|
45 |
-
def extract_text_from_excel(
|
46 |
all_text = []
|
47 |
try:
|
48 |
-
xls = pd.ExcelFile(
|
49 |
except Exception as e:
|
50 |
raise ValueError(f"❌ Error reading Excel file: {e}")
|
51 |
for sheet_name in xls.sheet_names:
|
@@ -115,8 +115,8 @@ def stream_report(agent, file: gr.File, full_output: str) -> Generator:
|
|
115 |
yield "❌ Please upload a valid Excel file.", None, ""
|
116 |
return
|
117 |
|
118 |
-
|
119 |
-
text = extract_text_from_excel(
|
120 |
chunks = split_text_into_chunks(text)
|
121 |
|
122 |
for i, chunk in enumerate(chunks):
|
|
|
42 |
def estimate_tokens(text: str) -> int:
|
43 |
return len(text) // 3.5 + 1
|
44 |
|
45 |
+
def extract_text_from_excel(file_obj: Union[str, os.PathLike, 'file']) -> str:
|
46 |
all_text = []
|
47 |
try:
|
48 |
+
xls = pd.ExcelFile(file_obj)
|
49 |
except Exception as e:
|
50 |
raise ValueError(f"❌ Error reading Excel file: {e}")
|
51 |
for sheet_name in xls.sheet_names:
|
|
|
115 |
yield "❌ Please upload a valid Excel file.", None, ""
|
116 |
return
|
117 |
|
118 |
+
# Support both uploaded file objects and file paths
|
119 |
+
text = extract_text_from_excel(file if hasattr(file, "read") else file.name)
|
120 |
chunks = split_text_into_chunks(text)
|
121 |
|
122 |
for i, chunk in enumerate(chunks):
|