Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -346,11 +346,10 @@ def create_interface():
|
|
346 |
processor = URLProcessor()
|
347 |
file_processor = FileProcessor()
|
348 |
results = []
|
349 |
-
|
350 |
-
|
351 |
url_list = re.split(r'[,\n]', urls)
|
352 |
url_list = [url.strip() for url in url_list if url.strip()]
|
353 |
-
|
354 |
for url in url_list:
|
355 |
validation = processor.validate_url(url)
|
356 |
if validation.get('is_valid'):
|
@@ -362,11 +361,9 @@ def create_interface():
|
|
362 |
'content': content,
|
363 |
'timestamp': datetime.now().isoformat()
|
364 |
})
|
365 |
-
|
366 |
# Process files
|
367 |
if file:
|
368 |
results.extend(file_processor.process_file(file))
|
369 |
-
|
370 |
# Process text input
|
371 |
if text:
|
372 |
cleaned_text = processor.advanced_text_cleaning(text)
|
@@ -375,22 +372,18 @@ def create_interface():
|
|
375 |
'content': cleaned_text,
|
376 |
'timestamp': datetime.now().isoformat()
|
377 |
})
|
378 |
-
|
379 |
# Generate output
|
380 |
if results:
|
381 |
output_dir = Path('output') / datetime.now().strftime('%Y-%m-%d')
|
382 |
output_dir.mkdir(parents=True, exist_ok=True)
|
383 |
output_path = output_dir / f'processed_{int(time.time())}.json'
|
384 |
-
|
385 |
with open(output_path, 'w', encoding='utf-8') as f:
|
386 |
json.dump(results, f, ensure_ascii=False, indent=2)
|
387 |
-
|
388 |
summary = f"Processed {len(results)} items successfully!"
|
389 |
json_data = json.dumps(results, indent=2) # Prepare JSON for QR code
|
390 |
return str(output_path), summary, json_data # Return JSON for editor
|
391 |
else:
|
392 |
return None, "No valid content to process.", ""
|
393 |
-
|
394 |
except Exception as e:
|
395 |
logger.error(f"Processing error: {e}")
|
396 |
return None, f"Error: {str(e)}", ""
|
|
|
346 |
processor = URLProcessor()
|
347 |
file_processor = FileProcessor()
|
348 |
results = []
|
349 |
+
# Process URLs
|
350 |
+
if urls:
|
351 |
url_list = re.split(r'[,\n]', urls)
|
352 |
url_list = [url.strip() for url in url_list if url.strip()]
|
|
|
353 |
for url in url_list:
|
354 |
validation = processor.validate_url(url)
|
355 |
if validation.get('is_valid'):
|
|
|
361 |
'content': content,
|
362 |
'timestamp': datetime.now().isoformat()
|
363 |
})
|
|
|
364 |
# Process files
|
365 |
if file:
|
366 |
results.extend(file_processor.process_file(file))
|
|
|
367 |
# Process text input
|
368 |
if text:
|
369 |
cleaned_text = processor.advanced_text_cleaning(text)
|
|
|
372 |
'content': cleaned_text,
|
373 |
'timestamp': datetime.now().isoformat()
|
374 |
})
|
|
|
375 |
# Generate output
|
376 |
if results:
|
377 |
output_dir = Path('output') / datetime.now().strftime('%Y-%m-%d')
|
378 |
output_dir.mkdir(parents=True, exist_ok=True)
|
379 |
output_path = output_dir / f'processed_{int(time.time())}.json'
|
|
|
380 |
with open(output_path, 'w', encoding='utf-8') as f:
|
381 |
json.dump(results, f, ensure_ascii=False, indent=2)
|
|
|
382 |
summary = f"Processed {len(results)} items successfully!"
|
383 |
json_data = json.dumps(results, indent=2) # Prepare JSON for QR code
|
384 |
return str(output_path), summary, json_data # Return JSON for editor
|
385 |
else:
|
386 |
return None, "No valid content to process.", ""
|
|
|
387 |
except Exception as e:
|
388 |
logger.error(f"Processing error: {e}")
|
389 |
return None, f"Error: {str(e)}", ""
|