cr8 commited on
Commit
fa1ca7f
·
verified ·
1 Parent(s): a62fe83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -1,13 +1,32 @@
1
  import gradio as gr
2
  import os
3
 
4
- # Function to serve the HTML file
5
- def serve_html():
6
- with open("index.html", "r") as file:
7
- return file.read()
 
 
 
 
 
 
 
8
 
9
- # Create a Gradio Interface
10
- iface = gr.Interface(fn=serve_html, inputs=None, outputs="html", live=True)
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Launch the Gradio app
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)