Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import tempfile
|
|
6 |
import zipfile
|
7 |
import shutil
|
8 |
from pathlib import Path
|
|
|
9 |
|
10 |
# Define target sizes for different viewports
|
11 |
SIZES = [
|
@@ -64,8 +65,8 @@ def process_image(input_image):
|
|
64 |
processed_paths = [] # Initialize the list outside try block
|
65 |
|
66 |
try:
|
67 |
-
#
|
68 |
-
img = Image.
|
69 |
|
70 |
# Convert to RGB if necessary
|
71 |
if img.mode != 'RGB':
|
@@ -108,7 +109,7 @@ def process_image(input_image):
|
|
108 |
os.rmdir(temp_dir)
|
109 |
except:
|
110 |
pass
|
111 |
-
|
112 |
# Create Gradio interface
|
113 |
with gr.Blocks(title="Responsive Image Generator") as app:
|
114 |
gr.Markdown("""
|
@@ -124,7 +125,7 @@ with gr.Blocks(title="Responsive Image Generator") as app:
|
|
124 |
with gr.Column():
|
125 |
input_image = gr.Image(
|
126 |
label="Upload Original Image",
|
127 |
-
type="
|
128 |
)
|
129 |
process_btn = gr.Button("Process Image")
|
130 |
|
@@ -142,5 +143,4 @@ with gr.Blocks(title="Responsive Image Generator") as app:
|
|
142 |
outputs=[output_zip, output_html, output_message]
|
143 |
)
|
144 |
|
145 |
-
# Launch the app
|
146 |
app.launch()
|
|
|
6 |
import zipfile
|
7 |
import shutil
|
8 |
from pathlib import Path
|
9 |
+
import numpy as np
|
10 |
|
11 |
# Define target sizes for different viewports
|
12 |
SIZES = [
|
|
|
65 |
processed_paths = [] # Initialize the list outside try block
|
66 |
|
67 |
try:
|
68 |
+
# Convert numpy array to PIL Image
|
69 |
+
img = Image.fromarray(input_image)
|
70 |
|
71 |
# Convert to RGB if necessary
|
72 |
if img.mode != 'RGB':
|
|
|
109 |
os.rmdir(temp_dir)
|
110 |
except:
|
111 |
pass
|
112 |
+
|
113 |
# Create Gradio interface
|
114 |
with gr.Blocks(title="Responsive Image Generator") as app:
|
115 |
gr.Markdown("""
|
|
|
125 |
with gr.Column():
|
126 |
input_image = gr.Image(
|
127 |
label="Upload Original Image",
|
128 |
+
type="numpy" # Changed to numpy type for better compatibility
|
129 |
)
|
130 |
process_btn = gr.Button("Process Image")
|
131 |
|
|
|
143 |
outputs=[output_zip, output_html, output_message]
|
144 |
)
|
145 |
|
|
|
146 |
app.launch()
|