Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -463,7 +463,7 @@ def generate_qr_codes(data: Union[str, Dict, List], combined: bool = True) -> Li
|
|
463 |
|
464 |
def create_modern_interface():
|
465 |
"""Create a modern and visually appealing Gradio interface"""
|
466 |
-
|
467 |
# Modern CSS styling
|
468 |
css = """
|
469 |
/* Modern color scheme */
|
@@ -476,7 +476,6 @@ def create_modern_interface():
|
|
476 |
--error-color: #f56565;
|
477 |
--warning-color: #ed8936;
|
478 |
}
|
479 |
-
|
480 |
/* Container styling */
|
481 |
.container {
|
482 |
max-width: 1200px;
|
@@ -486,7 +485,6 @@ def create_modern_interface():
|
|
486 |
border-radius: 1rem;
|
487 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
488 |
}
|
489 |
-
|
490 |
/* Component styling */
|
491 |
.input-container {
|
492 |
background-color: white;
|
@@ -495,7 +493,6 @@ def create_modern_interface():
|
|
495 |
border: 1px solid #e2e8f0;
|
496 |
margin-bottom: 1rem;
|
497 |
}
|
498 |
-
|
499 |
/* Button styling */
|
500 |
.primary-button {
|
501 |
background-color: var(--primary-color);
|
@@ -506,23 +503,19 @@ def create_modern_interface():
|
|
506 |
cursor: pointer;
|
507 |
transition: all 0.2s;
|
508 |
}
|
509 |
-
|
510 |
.primary-button:hover {
|
511 |
background-color: var(--accent-color);
|
512 |
transform: translateY(-1px);
|
513 |
}
|
514 |
-
|
515 |
/* Status messages */
|
516 |
.status {
|
517 |
padding: 1rem;
|
518 |
border-radius: 0.375rem;
|
519 |
margin: 1rem 0;
|
520 |
}
|
521 |
-
|
522 |
.status.success { background-color: #f0fff4; color: var(--success-color); }
|
523 |
.status.error { background-color: #fff5f5; color: var(--error-color); }
|
524 |
.status.warning { background-color: #fffaf0; color: var(--warning-color); }
|
525 |
-
|
526 |
/* Gallery styling */
|
527 |
.gallery {
|
528 |
display: grid;
|
@@ -533,27 +526,23 @@ def create_modern_interface():
|
|
533 |
border-radius: 0.5rem;
|
534 |
border: 1px solid #e2e8f0;
|
535 |
}
|
536 |
-
|
537 |
.gallery img {
|
538 |
width: 100%;
|
539 |
height: auto;
|
540 |
border-radius: 0.375rem;
|
541 |
transition: transform 0.2s;
|
542 |
}
|
543 |
-
|
544 |
.gallery img:hover {
|
545 |
transform: scale(1.05);
|
546 |
}
|
547 |
"""
|
548 |
-
|
549 |
# Create interface with modern design
|
550 |
with gr.Blocks(css=css, title="Advanced Data Processor & QR Generator") as interface:
|
551 |
gr.Markdown("""
|
552 |
# π Advanced Data Processing & QR Code Generator
|
553 |
-
|
554 |
Transform your data into beautifully designed, sequenced QR codes with our cutting-edge processor.
|
555 |
""")
|
556 |
-
|
557 |
with gr.Tab("π URL Processing"):
|
558 |
url_input = gr.Textbox(
|
559 |
label="Enter URLs (comma or newline separated)",
|
@@ -561,14 +550,14 @@ def create_modern_interface():
|
|
561 |
placeholder="https://example1.com\nhttps://example2.com",
|
562 |
value=""
|
563 |
)
|
564 |
-
|
565 |
with gr.Tab("π File Input"):
|
566 |
file_input = gr.File(
|
567 |
label="Upload Files",
|
568 |
-
file_types=["text
|
|
|
|
|
569 |
file_count="multiple"
|
570 |
)
|
571 |
-
|
572 |
with gr.Tab("π JSON Input"):
|
573 |
text_input = gr.TextArea(
|
574 |
label="Direct JSON Input",
|
@@ -576,11 +565,9 @@ def create_modern_interface():
|
|
576 |
placeholder="Paste your JSON data here...",
|
577 |
value=""
|
578 |
)
|
579 |
-
|
580 |
with gr.Row():
|
581 |
example_btn = gr.Button("π Load Example", variant="secondary")
|
582 |
clear_btn = gr.Button("ποΈ Clear", variant="secondary")
|
583 |
-
|
584 |
with gr.Row():
|
585 |
combine_data = gr.Checkbox(
|
586 |
label="Combine all data into sequence",
|
@@ -591,7 +578,6 @@ def create_modern_interface():
|
|
591 |
"π Process & Generate QR",
|
592 |
variant="primary"
|
593 |
)
|
594 |
-
|
595 |
# Output components
|
596 |
output_json = gr.JSON(label="Processed Data")
|
597 |
output_gallery = gr.Gallery(
|
@@ -660,7 +646,6 @@ def create_modern_interface():
|
|
660 |
if urls and urls.strip():
|
661 |
url_list = re.split(r'[,\n]', urls)
|
662 |
url_list = [url.strip() for url in url_list if url.strip()]
|
663 |
-
|
664 |
for url in url_list:
|
665 |
validation = url_processor.validate_url(url)
|
666 |
if validation['is_valid']:
|
@@ -693,7 +678,6 @@ def create_modern_interface():
|
|
693 |
return None, [], "β Failed to generate QR codes"
|
694 |
else:
|
695 |
return None, [], "β οΈ No valid content to process"
|
696 |
-
|
697 |
except Exception as e:
|
698 |
logger.error(f"Processing error: {e}")
|
699 |
return None, [], f"β Error: {str(e)}"
|
@@ -710,28 +694,24 @@ def create_modern_interface():
|
|
710 |
# Add helpful documentation
|
711 |
gr.Markdown("""
|
712 |
### π Features
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
- Each QR code contains metadata for proper sequencing
|
732 |
-
- Hover over QR codes in the gallery to see details
|
733 |
-
""")
|
734 |
-
|
735 |
return interface
|
736 |
|
737 |
def main():
|
@@ -742,7 +722,7 @@ def main():
|
|
742 |
|
743 |
# Create and launch interface
|
744 |
interface = create_modern_interface()
|
745 |
-
|
746 |
# Launch with configuration
|
747 |
interface.launch(
|
748 |
share=False,
|
|
|
463 |
|
464 |
def create_modern_interface():
|
465 |
"""Create a modern and visually appealing Gradio interface"""
|
466 |
+
|
467 |
# Modern CSS styling
|
468 |
css = """
|
469 |
/* Modern color scheme */
|
|
|
476 |
--error-color: #f56565;
|
477 |
--warning-color: #ed8936;
|
478 |
}
|
|
|
479 |
/* Container styling */
|
480 |
.container {
|
481 |
max-width: 1200px;
|
|
|
485 |
border-radius: 1rem;
|
486 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
487 |
}
|
|
|
488 |
/* Component styling */
|
489 |
.input-container {
|
490 |
background-color: white;
|
|
|
493 |
border: 1px solid #e2e8f0;
|
494 |
margin-bottom: 1rem;
|
495 |
}
|
|
|
496 |
/* Button styling */
|
497 |
.primary-button {
|
498 |
background-color: var(--primary-color);
|
|
|
503 |
cursor: pointer;
|
504 |
transition: all 0.2s;
|
505 |
}
|
|
|
506 |
.primary-button:hover {
|
507 |
background-color: var(--accent-color);
|
508 |
transform: translateY(-1px);
|
509 |
}
|
|
|
510 |
/* Status messages */
|
511 |
.status {
|
512 |
padding: 1rem;
|
513 |
border-radius: 0.375rem;
|
514 |
margin: 1rem 0;
|
515 |
}
|
|
|
516 |
.status.success { background-color: #f0fff4; color: var(--success-color); }
|
517 |
.status.error { background-color: #fff5f5; color: var(--error-color); }
|
518 |
.status.warning { background-color: #fffaf0; color: var(--warning-color); }
|
|
|
519 |
/* Gallery styling */
|
520 |
.gallery {
|
521 |
display: grid;
|
|
|
526 |
border-radius: 0.5rem;
|
527 |
border: 1px solid #e2e8f0;
|
528 |
}
|
|
|
529 |
.gallery img {
|
530 |
width: 100%;
|
531 |
height: auto;
|
532 |
border-radius: 0.375rem;
|
533 |
transition: transform 0.2s;
|
534 |
}
|
|
|
535 |
.gallery img:hover {
|
536 |
transform: scale(1.05);
|
537 |
}
|
538 |
"""
|
|
|
539 |
# Create interface with modern design
|
540 |
with gr.Blocks(css=css, title="Advanced Data Processor & QR Generator") as interface:
|
541 |
gr.Markdown("""
|
542 |
# π Advanced Data Processing & QR Code Generator
|
543 |
+
|
544 |
Transform your data into beautifully designed, sequenced QR codes with our cutting-edge processor.
|
545 |
""")
|
|
|
546 |
with gr.Tab("π URL Processing"):
|
547 |
url_input = gr.Textbox(
|
548 |
label="Enter URLs (comma or newline separated)",
|
|
|
550 |
placeholder="https://example1.com\nhttps://example2.com",
|
551 |
value=""
|
552 |
)
|
|
|
553 |
with gr.Tab("π File Input"):
|
554 |
file_input = gr.File(
|
555 |
label="Upload Files",
|
556 |
+
file_types=["text", ".zip", ".json",
|
557 |
+
".tar", ".gz", ".bz2", ".7z", ".rar",
|
558 |
+
".pdf", ".doc", ".docx", ".rtf", ".odt"],
|
559 |
file_count="multiple"
|
560 |
)
|
|
|
561 |
with gr.Tab("π JSON Input"):
|
562 |
text_input = gr.TextArea(
|
563 |
label="Direct JSON Input",
|
|
|
565 |
placeholder="Paste your JSON data here...",
|
566 |
value=""
|
567 |
)
|
|
|
568 |
with gr.Row():
|
569 |
example_btn = gr.Button("π Load Example", variant="secondary")
|
570 |
clear_btn = gr.Button("ποΈ Clear", variant="secondary")
|
|
|
571 |
with gr.Row():
|
572 |
combine_data = gr.Checkbox(
|
573 |
label="Combine all data into sequence",
|
|
|
578 |
"π Process & Generate QR",
|
579 |
variant="primary"
|
580 |
)
|
|
|
581 |
# Output components
|
582 |
output_json = gr.JSON(label="Processed Data")
|
583 |
output_gallery = gr.Gallery(
|
|
|
646 |
if urls and urls.strip():
|
647 |
url_list = re.split(r'[,\n]', urls)
|
648 |
url_list = [url.strip() for url in url_list if url.strip()]
|
|
|
649 |
for url in url_list:
|
650 |
validation = url_processor.validate_url(url)
|
651 |
if validation['is_valid']:
|
|
|
678 |
return None, [], "β Failed to generate QR codes"
|
679 |
else:
|
680 |
return None, [], "β οΈ No valid content to process"
|
|
|
681 |
except Exception as e:
|
682 |
logger.error(f"Processing error: {e}")
|
683 |
return None, [], f"β Error: {str(e)}"
|
|
|
694 |
# Add helpful documentation
|
695 |
gr.Markdown("""
|
696 |
### π Features
|
697 |
+
- **Complete URL Scraping**: Extracts every character from web pages
|
698 |
+
- **Advanced File Processing**: Full content extraction from various text-based files and common archives
|
699 |
+
- **Smart JSON Handling**: Processes any size JSON with automatic chunking
|
700 |
+
- **Sequential QR Codes**: Maintains data integrity across multiple codes
|
701 |
+
- **Modern Design**: Clean, responsive interface with visual feedback
|
702 |
+
|
703 |
+
### π‘ Tips
|
704 |
+
1. **URLs**: Enter multiple URLs separated by commas or newlines
|
705 |
+
2. **Files**: Upload various text-based files (e.g., .txt, .md, .csv), JSON files (.json), or common archives (.zip, .tar, .gz)
|
706 |
+
3. **JSON**: Use the example button to see the expected format or upload a .json file
|
707 |
+
4. **QR Codes**: Choose whether to combine data into sequential codes
|
708 |
+
5. **Processing**: Monitor the status for real-time feedback
|
709 |
+
|
710 |
+
### π¨ Output
|
711 |
+
- Generated QR codes are saved in the `output/qr_codes` directory
|
712 |
+
- Each QR code contains metadata for proper sequencing
|
713 |
+
- Hover over QR codes in the gallery to see details
|
714 |
+
""")
|
|
|
|
|
|
|
|
|
715 |
return interface
|
716 |
|
717 |
def main():
|
|
|
722 |
|
723 |
# Create and launch interface
|
724 |
interface = create_modern_interface()
|
725 |
+
|
726 |
# Launch with configuration
|
727 |
interface.launch(
|
728 |
share=False,
|