Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,19 @@ import gradio as gr
|
|
| 2 |
import numpy as np
|
| 3 |
import zipfile
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
-
# Simple function to flip an image upside down
|
| 7 |
def flip_image(image):
|
| 8 |
-
|
| 9 |
image = Image.fromarray(np.uint8(image))
|
| 10 |
-
# Create
|
| 11 |
-
with
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return "image.zip"
|
| 14 |
|
| 15 |
-
# Create a simple GUI
|
| 16 |
gr.Interface(fn=flip_image,
|
| 17 |
inputs="image",
|
| 18 |
outputs="file",
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import zipfile
|
| 4 |
from PIL import Image
|
| 5 |
+
import tempfile
|
| 6 |
|
|
|
|
| 7 |
def flip_image(image):
|
|
|
|
| 8 |
image = Image.fromarray(np.uint8(image))
|
| 9 |
+
# Create a temporary file
|
| 10 |
+
with tempfile.NamedTemporaryFile(suffix='.jpg') as temp:
|
| 11 |
+
# Save the image to the temporary file
|
| 12 |
+
image.save(temp.name)
|
| 13 |
+
# Create zip file
|
| 14 |
+
with zipfile.ZipFile("image.zip", 'w') as zip:
|
| 15 |
+
zip.write(temp.name)
|
| 16 |
return "image.zip"
|
| 17 |
|
|
|
|
| 18 |
gr.Interface(fn=flip_image,
|
| 19 |
inputs="image",
|
| 20 |
outputs="file",
|