Spaces:
Running
Running
Update app2.py
Browse files
app2.py
CHANGED
@@ -496,6 +496,164 @@ def generate_qr_codes(data: Union[str, Dict, List], combined: bool = True) -> Li
|
|
496 |
logger.error(f"QR code generation error: {e}")
|
497 |
return []
|
498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
def create_modern_interface():
|
500 |
"""Create a modern and visually appealing Gradio interface"""
|
501 |
|
@@ -596,6 +754,30 @@ def create_modern_interface():
|
|
596 |
"""
|
597 |
# Create interface with modern design
|
598 |
with gr.Blocks(css=css, title="Advanced Data Processor & QR Generator") as interface:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
599 |
qr_code_paths = gr.State([])
|
600 |
gr.Markdown("""
|
601 |
# π Advanced Data Processing & QR Code Generator
|
@@ -612,7 +794,7 @@ def create_modern_interface():
|
|
612 |
with gr.Tab("π File Input"):
|
613 |
file_input = gr.File(
|
614 |
label="Upload Files",
|
615 |
-
file_types=
|
616 |
file_count="multiple"
|
617 |
)
|
618 |
with gr.Tab("π JSON Input"):
|
|
|
496 |
logger.error(f"QR code generation error: {e}")
|
497 |
return []
|
498 |
|
499 |
+
def create_modern_interface():
|
500 |
+
"""Create a modern and visually appealing Gradio interface"""
|
501 |
+
|
502 |
+
# Modern CSS styling
|
503 |
+
css = """
|
504 |
+
/* Modern color scheme */
|
505 |
+
:root {
|
506 |
+
--primary-color: #1a365d;
|
507 |
+
--secondary-color: #2d3748;
|
508 |
+
--accent-color: #4299e1;
|
509 |
+
--background-color: #f7fafc;
|
510 |
+
--success-color: #48bb78;
|
511 |
+
--error-color: #f56565;
|
512 |
+
--warning-color: #ed8936;
|
513 |
+
}
|
514 |
+
/* Container styling */
|
515 |
+
.container {
|
516 |
+
max-width: 1200px;
|
517 |
+
margin: auto;
|
518 |
+
padding: 2rem;
|
519 |
+
background-color: var(--background-color);
|
520 |
+
border-radius: 1rem;
|
521 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
522 |
+
}
|
523 |
+
/* Component styling */
|
524 |
+
.input-container {
|
525 |
+
background-color: white;
|
526 |
+
padding: 1.5rem;
|
527 |
+
border-radius: 0.5rem;
|
528 |
+
border: 1px solid #e2e8f0;
|
529 |
+
margin-bottom: 1rem;
|
530 |
+
}
|
531 |
+
/* Button styling */
|
532 |
+
.primary-button {
|
533 |
+
background-color: var(--primary-color);
|
534 |
+
color: white;
|
535 |
+
padding: 0.75rem 1.5rem;
|
536 |
+
border-radius: 0.375rem;
|
537 |
+
border: none;
|
538 |
+
cursor: pointer;
|
539 |
+
transition: all 0.2s;
|
540 |
+
}
|
541 |
+
.primary-button:hover {
|
542 |
+
background-color: var(--accent-color);
|
543 |
+
transform: translateY(-1px);
|
544 |
+
}
|
545 |
+
/* Status messages */
|
546 |
+
.status {
|
547 |
+
padding: 1rem;
|
548 |
+
border-radius: 0.375rem;
|
549 |
+
margin: 1rem 0;
|
550 |
+
}
|
551 |
+
.status.success { background-color: #f0fff4; color: var(--success-color); }
|
552 |
+
.status.error { background-color: #fff5f5; color: var(--error-color); }
|
553 |
+
.status.warning { background-color: #fffaf0; color: var(--warning-color); }
|
554 |
+
/* Gallery styling */
|
555 |
+
.gallery {
|
556 |
+
display: grid;
|
557 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
558 |
+
gap: 1rem;
|
559 |
+
padding: 1rem;
|
560 |
+
background-color: white;
|
561 |
+
border-radius: 0.5rem;
|
562 |
+
border: 1px solid #e2e8f0;
|
563 |
+
}
|
564 |
+
.gallery img {
|
565 |
+
width: 100%;
|
566 |
+
height: auto;
|
567 |
+
border-radius: 0.375rem;
|
568 |
+
transition: transform 0.2s;
|
569 |
+
}
|
570 |
+
.gallery img:hover {
|
571 |
+
transform: scale(1.05);
|
572 |
+
}
|
573 |
+
/* QR Code Viewport Styling */
|
574 |
+
.viewport-container {
|
575 |
+
display: grid;
|
576 |
+
gap: 0.5rem;
|
577 |
+
padding: 1rem;
|
578 |
+
background-color: white;
|
579 |
+
border-radius: 0.5rem;
|
580 |
+
border: 1px solid #e2e8f0;
|
581 |
+
margin-top: 1rem;
|
582 |
+
}
|
583 |
+
.viewport-item {
|
584 |
+
display: flex;
|
585 |
+
flex-direction: column;
|
586 |
+
align-items: center;
|
587 |
+
}
|
588 |
+
.viewport-item img {
|
589 |
+
width: 100%;
|
590 |
+
height: auto;
|
591 |
+
border-radius: 0.375rem;
|
592 |
+
transition: transform 0.2s;
|
593 |
+
max-width: 150px; /* Adjust as needed */
|
594 |
+
max-height: 150px; /* Adjust as needed */
|
595 |
+
}
|
596 |
+
"""
|
597 |
+
# Create interface with modern design
|
598 |
+
with gr.Blocks(css=css, title="Advanced Data Processor & QR Generator") as interface:
|
599 |
+
interface.head += """
|
600 |
+
<script>
|
601 |
+
let enabledStates = [];
|
602 |
+
|
603 |
+
function updateEnabledStates(checkbox) {
|
604 |
+
const index = parseInt(checkbox.dataset.index);
|
605 |
+
if (checkbox.checked) {
|
606 |
+
if (!enabledStates.includes(index)) {
|
607 |
+
enabledStates.push(index);
|
608 |
+
}
|
609 |
+
} else {
|
610 |
+
enabledStates = enabledStates.filter(item => item !== index);
|
611 |
+
}
|
612 |
+
// Send the updated state back to Gradio (you might need to adjust the target component)
|
613 |
+
const enabled_qr_codes_component = document.querySelector('[data-component-type="state"][data-state-name="enabled_qr_codes"]');
|
614 |
+
if (enabled_qr_codes_component) {
|
615 |
+
enabled_qr_codes_component.value = JSON.stringify(enabledStates);
|
616 |
+
enabled_qr_codes_component.dispatchEvent(new Event('input')); // Trigger update
|
617 |
+
}
|
618 |
+
console.log("Enabled QR Code Indices:", enabledStates);
|
619 |
+
// You might want to trigger an update of the viewport here if needed
|
620 |
+
}
|
621 |
+
</script>
|
622 |
+
"""
|
623 |
+
qr_code_paths = gr.State([])
|
624 |
+
# ... (rest of the Gradio interface definition) ...
|
625 |
+
with gr.Tab("πΌοΈ QR Code Viewport") as viewport_tab:
|
626 |
+
viewport_output = gr.HTML(label="QR Code Sequence Viewport")
|
627 |
+
enabled_qr_codes = gr.State([]) # To store the enabled/disabled state
|
628 |
+
# ... (rest of the function) ...
|
629 |
+
viewport_tab.select(update_viewport, inputs=[qr_code_paths, enabled_qr_codes], outputs=[viewport_output])
|
630 |
+
# ... (rest of the function) ...
|
631 |
+
Important Considerations and Next Steps:
|
632 |
+
|
633 |
+
State Management: The JavaScript code updates a global variable enabledStates. While this works for a basic example, for more complex applications, you might want to manage the state more robustly within Gradio.
|
634 |
+
Viewport Update: Currently, the viewport is updated only when you switch to the "QR Code Viewport" tab. If you want the viewport to update immediately after enabling/disabling a QR code, you'll need to trigger the update_viewport function from the JavaScript code. This typically involves using Gradio's Remote Functions or a submit button.
|
635 |
+
Visualization of Result: The current implementation visualizes the enabled state with a green border. You might have a different idea for how the "result" of enabling/disabling should be visualized.
|
636 |
+
Scalability: For a very large number of QR codes, rendering all of them in HTML might become inefficient. You might need to consider techniques like pagination or virtualization.
|
637 |
+
With these changes, the application will now have a basic QR Code Viewport with enable/disable functionality. You can further refine the UI and the interaction based on your specific needs.
|
638 |
+
|
639 |
+
|
640 |
+
|
641 |
+
|
642 |
+
|
643 |
+
|
644 |
+
its not letting me add my expected filetypes?
|
645 |
+
|
646 |
+
|
647 |
+
|
648 |
+
Show thinking
|
649 |
+
You are right to point that out. My apologies for the continued oversight. While the intent with file_types=["*"] was to be open, Gradio's gr.File component might interpret that differently or it might not be the intended way to accept all types.
|
650 |
+
|
651 |
+
According to the Gradio documentation, to accept all file types, you should set the file_types parameter to None.
|
652 |
+
|
653 |
+
Let's make that change in the create_modern_interface function. Here's the updated section:
|
654 |
+
|
655 |
+
Python
|
656 |
+
|
657 |
def create_modern_interface():
|
658 |
"""Create a modern and visually appealing Gradio interface"""
|
659 |
|
|
|
754 |
"""
|
755 |
# Create interface with modern design
|
756 |
with gr.Blocks(css=css, title="Advanced Data Processor & QR Generator") as interface:
|
757 |
+
interface.head += """
|
758 |
+
<script>
|
759 |
+
let enabledStates = [];
|
760 |
+
|
761 |
+
function updateEnabledStates(checkbox) {
|
762 |
+
const index = parseInt(checkbox.dataset.index);
|
763 |
+
if (checkbox.checked) {
|
764 |
+
if (!enabledStates.includes(index)) {
|
765 |
+
enabledStates.push(index);
|
766 |
+
}
|
767 |
+
} else {
|
768 |
+
enabledStates = enabledStates.filter(item => item !== index);
|
769 |
+
}
|
770 |
+
// Send the updated state back to Gradio (you might need to adjust the target component)
|
771 |
+
const enabled_qr_codes_component = document.querySelector('[data-component-type="state"][data-state-name="enabled_qr_codes"]');
|
772 |
+
if (enabled_qr_codes_component) {
|
773 |
+
enabled_qr_codes_component.value = JSON.stringify(enabledStates);
|
774 |
+
enabled_qr_codes_component.dispatchEvent(new Event('input')); // Trigger update
|
775 |
+
}
|
776 |
+
console.log("Enabled QR Code Indices:", enabledStates);
|
777 |
+
// You might want to trigger an update of the viewport here if needed
|
778 |
+
}
|
779 |
+
</script>
|
780 |
+
"""
|
781 |
qr_code_paths = gr.State([])
|
782 |
gr.Markdown("""
|
783 |
# π Advanced Data Processing & QR Code Generator
|
|
|
794 |
with gr.Tab("π File Input"):
|
795 |
file_input = gr.File(
|
796 |
label="Upload Files",
|
797 |
+
file_types=None, # Accept all file types
|
798 |
file_count="multiple"
|
799 |
)
|
800 |
with gr.Tab("π JSON Input"):
|