Ali2206 commited on
Commit
8d865c3
·
verified ·
1 Parent(s): 6f1a22c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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(file_path: str) -> str:
46
  all_text = []
47
  try:
48
- xls = pd.ExcelFile(file_path)
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
- filepath = file.name if hasattr(file, "name") else file
119
- text = extract_text_from_excel(filepath)
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):