Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
# Function to
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# Function to handle image upload and layout setting
|
| 5 |
+
def process_images(layout, image_files):
|
| 6 |
+
# Save uploaded images
|
| 7 |
+
img_paths = []
|
| 8 |
+
for img_file in image_files:
|
| 9 |
+
img_path = f"temp_images/{img_file.name}"
|
| 10 |
+
img_file.save(img_path)
|
| 11 |
+
img_paths.append(img_path)
|
| 12 |
+
|
| 13 |
+
# Return the layout and image paths to the front-end (HTML and JS will take care of it)
|
| 14 |
+
return layout, img_paths
|
| 15 |
|
| 16 |
+
# Gradio Interface setup
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=process_images,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.Dropdown(
|
| 21 |
+
label="Choose Grid Layout",
|
| 22 |
+
choices=["1x2", "1x3", "1x4", "2x2", "2x3", "random", "jagged4", "split6", "chaos5"],
|
| 23 |
+
default="3x3"
|
| 24 |
+
),
|
| 25 |
+
gr.File(label="Upload Images", type="file", multiple=True) # Multiple image upload
|
| 26 |
+
],
|
| 27 |
+
outputs=["text", "json"], # We'll output a layout and list of image paths
|
| 28 |
+
live=True # Updates in real-time
|
| 29 |
+
)
|
| 30 |
|
| 31 |
+
# Run Gradio app
|
| 32 |
+
iface.launch(share=True)
|