acecalisto3 commited on
Commit
4dd743a
·
verified ·
1 Parent(s): 940f903

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -203,7 +203,7 @@ class FileProcessor:
203
  zip_results = self._process_zip_file(file_path)
204
  combined_data.extend(zip_results)
205
  elif self.is_text_file(file_path):
206
- file_results = self._process_single_file(file_path)
207
  combined_data.extend(file_results)
208
  else:
209
  logger.warning(f"Unsupported file type: {file_path}")
@@ -212,27 +212,22 @@ class FileProcessor:
212
  logger.error(f"Error processing files: {str(e)}")
213
 
214
  return combined_data
215
- def _process_zip_file(self, zip_path: str, temp_dir: str) -> List[Dict]:
216
- """Process ZIP file contents"""
 
217
  results = []
218
- with zipfile.ZipFile(zip_path, 'r') as zip_ref:
219
- zip_ref.extractall(temp_dir)
220
- for root, _, files in os.walk(temp_dir):
221
- for filename in files:
222
- filepath = os.path.join(root, filename)
223
- if self.is_text_file(filepath):
224
- try:
225
- with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
226
- content = f.read()
227
- if content.strip():
228
- results.append({
229
- "source": "file",
230
- "filename": filename,
231
- "content": content,
232
- "timestamp": datetime.now().isoformat()
233
- })
234
- except Exception as e:
235
- logger.error(f"Error reading file {filename}: {str(e)}")
236
  return results
237
 
238
  def _process_single_file(self, file) -> List[Dict]:
 
203
  zip_results = self._process_zip_file(file_path)
204
  combined_data.extend(zip_results)
205
  elif self.is_text_file(file_path):
206
+ file_results = self.process_single_file(file_path)
207
  combined_data.extend(file_results)
208
  else:
209
  logger.warning(f"Unsupported file type: {file_path}")
 
212
  logger.error(f"Error processing files: {str(e)}")
213
 
214
  return combined_data
215
+
216
+ def process_single_file(self, file_path: str) -> List[Dict]:
217
+ """Process a single file and extract its content."""
218
  results = []
219
+ try:
220
+ with open(file_path, 'r', encoding='utf-8', errors='ignore') as file:
221
+ content = file.read()
222
+ if content.strip():
223
+ results.append({
224
+ "source": "file",
225
+ "filename": os.path.basename(file_path),
226
+ "content": content,
227
+ "timestamp": datetime.now().isoformat()
228
+ })
229
+ except Exception as e:
230
+ logger.error(f"Error reading file {file_path}: {str(e)}")
 
 
 
 
 
 
231
  return results
232
 
233
  def _process_single_file(self, file) -> List[Dict]: