Spaces:
Running
Running
Update app.py
Browse files
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.
|
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 |
-
|
216 |
-
|
|
|
217 |
results = []
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
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]:
|