KingNish commited on
Commit
eb531b3
·
verified ·
1 Parent(s): f1bdb57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -120,8 +120,8 @@ def read_document(file, clean=True):
120
  return content, len(content)
121
  except Exception as e:
122
  return f"Error reading PDF: {e}", 0
123
- elif mime == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
124
- # XLSX Handling (unchanged)
125
  try:
126
  wb = load_workbook(io.BytesIO(file_content))
127
  content = ''
@@ -134,7 +134,7 @@ def read_document(file, clean=True):
134
  content = clean_text(content)
135
  return content, len(content)
136
  except Exception as e:
137
- return f"Error reading XLSX: {e}", 0
138
  elif mime == "text/plain":
139
  try:
140
  content = file_content.decode('utf-8')
@@ -151,17 +151,18 @@ def read_document(file, clean=True):
151
  return content, len(content)
152
  except Exception as e:
153
  return f"Error reading CSV file: {e}", 0
154
- elif mime == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
 
155
  try:
156
  return extract_text_from_docx(file_content, clean)
157
  except Exception as e:
158
- return f"Error reading DOCX: {e}", 0
159
- elif mime == "application/vnd.openxmlformats-officedocument.presentationml.presentation":
 
160
  try:
161
  return extract_text_from_pptx(file_content, clean)
162
  except Exception as e:
163
- return f"Error reading PPTX: {e}", 0
164
-
165
  else:
166
  try:
167
  content = file_content.decode('utf-8')
@@ -170,6 +171,7 @@ def read_document(file, clean=True):
170
  return content, len(content)
171
  except Exception as e:
172
  return f"Error reading file: {e}", 0
 
173
 
174
 
175
  # --- Chat Functions ---
 
120
  return content, len(content)
121
  except Exception as e:
122
  return f"Error reading PDF: {e}", 0
123
+ elif mime in ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-excel"]:
124
+ # XLSX and XLS Handling
125
  try:
126
  wb = load_workbook(io.BytesIO(file_content))
127
  content = ''
 
134
  content = clean_text(content)
135
  return content, len(content)
136
  except Exception as e:
137
+ return f"Error reading XLSX/XLS: {e}", 0
138
  elif mime == "text/plain":
139
  try:
140
  content = file_content.decode('utf-8')
 
151
  return content, len(content)
152
  except Exception as e:
153
  return f"Error reading CSV file: {e}", 0
154
+ elif mime in ["application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/msword", "application/vnd.oasis.opendocument.text"]:
155
+ # DOCX, DOC, and ODT Handling
156
  try:
157
  return extract_text_from_docx(file_content, clean)
158
  except Exception as e:
159
+ return f"Error reading DOCX/DOC/ODT: {e}", 0
160
+ elif mime in ["application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.ms-powerpoint", "application/vnd.oasis.opendocument.presentation"]:
161
+ # PPTX, PPT, and ODP Handling
162
  try:
163
  return extract_text_from_pptx(file_content, clean)
164
  except Exception as e:
165
+ return f"Error reading PPTX/PPT/ODP: {e}", 0
 
166
  else:
167
  try:
168
  content = file_content.decode('utf-8')
 
171
  return content, len(content)
172
  except Exception as e:
173
  return f"Error reading file: {e}", 0
174
+
175
 
176
 
177
  # --- Chat Functions ---