Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -158,15 +158,6 @@ class FileProcessor:
|
|
158 |
self.processed_zip_count = 0
|
159 |
self.max_zip_files = 5
|
160 |
|
161 |
-
def is_text_file(self, filepath: str) -> bool:
|
162 |
-
"""Check if file is a text file"""
|
163 |
-
try:
|
164 |
-
mime_type, _ = mimetypes.guess_type(filepath)
|
165 |
-
return (mime_type and mime_type.startswith('text/')) or \
|
166 |
-
(os.path.splitext(filepath)[1].lower() in self.supported_text_extensions)
|
167 |
-
except Exception:
|
168 |
-
return False
|
169 |
-
|
170 |
def process_files(self, files: Union[List[gr.File], List[str]]) -> List[Dict]:
|
171 |
"""Process multiple uploaded files and return a single JSON extraction"""
|
172 |
if not files:
|
@@ -212,6 +203,7 @@ 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) -> List[Dict]:
|
216 |
"""Process ZIP file contents more efficiently"""
|
217 |
results = []
|
@@ -223,7 +215,6 @@ class FileProcessor:
|
|
223 |
|
224 |
# Process each file directly from the zip without extracting all files
|
225 |
for filename in file_list:
|
226 |
-
# Check if it's a text file by extension
|
227 |
if any(filename.lower().endswith(ext) for ext in self.supported_text_extensions):
|
228 |
try:
|
229 |
with zip_ref.open(filename) as file:
|
@@ -241,27 +232,6 @@ class FileProcessor:
|
|
241 |
logger.error(f"Error processing ZIP file {zip_path}: {str(e)}")
|
242 |
return results
|
243 |
|
244 |
-
def _process_single_file(self, file_path: str) -> List[Dict]:
|
245 |
-
"""Process a single file and return its content"""
|
246 |
-
results = []
|
247 |
-
try:
|
248 |
-
file_stat = os.stat(file_path)
|
249 |
-
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
250 |
-
content = f.read()
|
251 |
-
results.append({
|
252 |
-
'source': 'file',
|
253 |
-
'filename': os.path.basename(file_path),
|
254 |
-
'file_size': file_stat.st_size,
|
255 |
-
'mime_type': mimetypes.guess_type(file_path)[0],
|
256 |
-
'created': datetime.fromtimestamp(file_stat.st_ctime).isoformat(),
|
257 |
-
'modified': datetime.fromtimestamp(file_stat.st_mtime).isoformat(),
|
258 |
-
'content': content,
|
259 |
-
'timestamp': datetime.now().isoformat()
|
260 |
-
})
|
261 |
-
except Exception as e:
|
262 |
-
logger.error(f"File processing error: {e}")
|
263 |
-
|
264 |
-
|
265 |
class Chatbot:
|
266 |
"""Simple chatbot that uses provided JSON data for responses."""
|
267 |
|
|
|
158 |
self.processed_zip_count = 0
|
159 |
self.max_zip_files = 5
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
def process_files(self, files: Union[List[gr.File], List[str]]) -> List[Dict]:
|
162 |
"""Process multiple uploaded files and return a single JSON extraction"""
|
163 |
if not files:
|
|
|
203 |
logger.error(f"Error processing files: {str(e)}")
|
204 |
|
205 |
return combined_data
|
206 |
+
|
207 |
def _process_zip_file(self, zip_path: str) -> List[Dict]:
|
208 |
"""Process ZIP file contents more efficiently"""
|
209 |
results = []
|
|
|
215 |
|
216 |
# Process each file directly from the zip without extracting all files
|
217 |
for filename in file_list:
|
|
|
218 |
if any(filename.lower().endswith(ext) for ext in self.supported_text_extensions):
|
219 |
try:
|
220 |
with zip_ref.open(filename) as file:
|
|
|
232 |
logger.error(f"Error processing ZIP file {zip_path}: {str(e)}")
|
233 |
return results
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
class Chatbot:
|
236 |
"""Simple chatbot that uses provided JSON data for responses."""
|
237 |
|