Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -458,7 +458,8 @@ def create_interface():
|
|
458 |
"""Process all input types and generate QR codes"""
|
459 |
try:
|
460 |
results = []
|
461 |
-
|
|
|
462 |
# Process text input first (since it's direct JSON)
|
463 |
if text and text.strip():
|
464 |
try:
|
@@ -469,13 +470,13 @@ def create_interface():
|
|
469 |
results.append(json_data)
|
470 |
except json.JSONDecodeError as e:
|
471 |
return None, [], f"β Invalid JSON format: {str(e)}"
|
472 |
-
|
473 |
# Process URLs if provided
|
474 |
if urls and urls.strip():
|
475 |
processor = URLProcessor()
|
476 |
url_list = re.split(r'[,\n]', urls)
|
477 |
url_list = [url.strip() for url in url_list if url.strip()]
|
478 |
-
|
479 |
for url in url_list:
|
480 |
validation = processor.validate_url(url)
|
481 |
if validation.get('is_valid'):
|
@@ -487,14 +488,13 @@ def create_interface():
|
|
487 |
'content': content,
|
488 |
'timestamp': datetime.now().isoformat()
|
489 |
})
|
490 |
-
|
491 |
# Process files if provided
|
492 |
if file:
|
493 |
-
file_processor = FileProcessor()
|
494 |
file_results = file_processor.process_file(file)
|
495 |
if file_results:
|
496 |
results.extend(file_results)
|
497 |
-
|
498 |
# Generate QR codes
|
499 |
if results:
|
500 |
if combine:
|
@@ -504,7 +504,7 @@ def create_interface():
|
|
504 |
qr_paths = generate_qr_code(combined_data, combined=False)
|
505 |
else:
|
506 |
qr_paths = generate_qr_code(results, combined=combine)
|
507 |
-
|
508 |
if qr_paths:
|
509 |
return (
|
510 |
results,
|
@@ -512,10 +512,10 @@ def create_interface():
|
|
512 |
f"β
Successfully processed {len(results)} items and generated {len(qr_paths)} QR code(s)!"
|
513 |
)
|
514 |
else:
|
515 |
-
return None, [], "
|
516 |
else:
|
517 |
return None, [], "β οΈ No valid content to process. Please provide some input data."
|
518 |
-
|
519 |
except Exception as e:
|
520 |
logger.error(f"Processing error: {e}")
|
521 |
return None, [], f"β Error: {str(e)}"
|
|
|
458 |
"""Process all input types and generate QR codes"""
|
459 |
try:
|
460 |
results = []
|
461 |
+
file_processor = FileProcessor() # Initialize file_processor here
|
462 |
+
|
463 |
# Process text input first (since it's direct JSON)
|
464 |
if text and text.strip():
|
465 |
try:
|
|
|
470 |
results.append(json_data)
|
471 |
except json.JSONDecodeError as e:
|
472 |
return None, [], f"β Invalid JSON format: {str(e)}"
|
473 |
+
|
474 |
# Process URLs if provided
|
475 |
if urls and urls.strip():
|
476 |
processor = URLProcessor()
|
477 |
url_list = re.split(r'[,\n]', urls)
|
478 |
url_list = [url.strip() for url in url_list if url.strip()]
|
479 |
+
|
480 |
for url in url_list:
|
481 |
validation = processor.validate_url(url)
|
482 |
if validation.get('is_valid'):
|
|
|
488 |
'content': content,
|
489 |
'timestamp': datetime.now().isoformat()
|
490 |
})
|
491 |
+
|
492 |
# Process files if provided
|
493 |
if file:
|
|
|
494 |
file_results = file_processor.process_file(file)
|
495 |
if file_results:
|
496 |
results.extend(file_results)
|
497 |
+
|
498 |
# Generate QR codes
|
499 |
if results:
|
500 |
if combine:
|
|
|
504 |
qr_paths = generate_qr_code(combined_data, combined=False)
|
505 |
else:
|
506 |
qr_paths = generate_qr_code(results, combined=combine)
|
507 |
+
|
508 |
if qr_paths:
|
509 |
return (
|
510 |
results,
|
|
|
512 |
f"β
Successfully processed {len(results)} items and generated {len(qr_paths)} QR code(s)!"
|
513 |
)
|
514 |
else:
|
515 |
+
return None, [], "β Failed to generate QR codes. Please check the input data."
|
516 |
else:
|
517 |
return None, [], "β οΈ No valid content to process. Please provide some input data."
|
518 |
+
|
519 |
except Exception as e:
|
520 |
logger.error(f"Processing error: {e}")
|
521 |
return None, [], f"β Error: {str(e)}"
|