Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from PIL import Image
|
| 3 |
import rembg
|
| 4 |
import io
|
|
|
|
| 5 |
|
| 6 |
def process_image(image, outline_size, outline_color, add_outline):
|
| 7 |
if image is None:
|
|
@@ -41,6 +42,15 @@ def process_image(image, outline_size, outline_color, add_outline):
|
|
| 41 |
|
| 42 |
return final_img
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# Gradio Interface
|
| 45 |
with gr.Blocks(title="Sticker Maker") as interface:
|
| 46 |
gr.Markdown("# Sticker Maker")
|
|
@@ -76,14 +86,7 @@ with gr.Blocks(title="Sticker Maker") as interface:
|
|
| 76 |
outputs=output_image,
|
| 77 |
)
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
def download_sticker(image):
|
| 81 |
-
if image:
|
| 82 |
-
img_byte_arr = io.BytesIO()
|
| 83 |
-
image.save(img_byte_arr, format="PNG")
|
| 84 |
-
img_byte_arr.seek(0)
|
| 85 |
-
return img_byte_arr
|
| 86 |
-
|
| 87 |
download_btn.click(
|
| 88 |
fn=download_sticker,
|
| 89 |
inputs=output_image,
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import rembg
|
| 4 |
import io
|
| 5 |
+
import tempfile
|
| 6 |
|
| 7 |
def process_image(image, outline_size, outline_color, add_outline):
|
| 8 |
if image is None:
|
|
|
|
| 42 |
|
| 43 |
return final_img
|
| 44 |
|
| 45 |
+
# Handle download
|
| 46 |
+
def download_sticker(image):
|
| 47 |
+
if image:
|
| 48 |
+
# Save image to a temporary file
|
| 49 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 50 |
+
image.save(temp_file.name, format="PNG")
|
| 51 |
+
temp_file.close()
|
| 52 |
+
return temp_file.name # Return the file path
|
| 53 |
+
|
| 54 |
# Gradio Interface
|
| 55 |
with gr.Blocks(title="Sticker Maker") as interface:
|
| 56 |
gr.Markdown("# Sticker Maker")
|
|
|
|
| 86 |
outputs=output_image,
|
| 87 |
)
|
| 88 |
|
| 89 |
+
# Enable download functionality
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
download_btn.click(
|
| 91 |
fn=download_sticker,
|
| 92 |
inputs=output_image,
|