cr8 commited on
Commit
edf79e8
·
verified ·
1 Parent(s): 0f5ea34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
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:
@@ -44,7 +45,7 @@ def process_image(image, outline_size, outline_color, add_outline):
44
  final_img.save(output_buffer, format="PNG")
45
  output_buffer.seek(0)
46
 
47
- return final_img
48
 
49
  # Gradio Interface
50
  with gr.Blocks(title="Sticker Maker") as interface:
@@ -62,7 +63,7 @@ with gr.Blocks(title="Sticker Maker") as interface:
62
 
63
  with gr.Column():
64
  output_image = gr.Image(
65
- label="Preview and Download", type="pil", interactive=False
66
  )
67
 
68
  # Show/hide outline options based on checkbox
@@ -73,19 +74,18 @@ with gr.Blocks(title="Sticker Maker") as interface:
73
  )
74
 
75
  # Process image and show result in the preview pane
76
- def process_and_return(image, outline_size, outline_color, add_outline):
77
- processed_image = process_image(image, outline_size, outline_color, add_outline)
78
- return processed_image # Return processed image for preview
 
79
 
 
80
  create_btn = gr.Button("Create Sticker", variant="primary")
81
  create_btn.click(
82
- fn=process_and_return,
83
  inputs=[image_upload, outline_size, outline_color, add_outline],
84
- outputs=output_image,
85
  )
86
 
87
- # Enable PNG download directly from the preview pane
88
- output_image.download(label="Download Sticker as PNG")
89
-
90
  if __name__ == "__main__":
91
  interface.launch(debug=True)
 
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:
 
45
  final_img.save(output_buffer, format="PNG")
46
  output_buffer.seek(0)
47
 
48
+ return final_img, output_buffer
49
 
50
  # Gradio Interface
51
  with gr.Blocks(title="Sticker Maker") as interface:
 
63
 
64
  with gr.Column():
65
  output_image = gr.Image(
66
+ label="Preview", type="pil", interactive=False
67
  )
68
 
69
  # Show/hide outline options based on checkbox
 
74
  )
75
 
76
  # Process image and show result in the preview pane
77
+ def process_and_download(image, outline_size, outline_color, add_outline):
78
+ processed_image, output_buffer = process_image(image, outline_size, outline_color, add_outline)
79
+ # Return the processed image for preview and the PNG file for download
80
+ return processed_image, output_buffer
81
 
82
+ # Add button to process image and provide preview
83
  create_btn = gr.Button("Create Sticker", variant="primary")
84
  create_btn.click(
85
+ fn=process_and_download,
86
  inputs=[image_upload, outline_size, outline_color, add_outline],
87
+ outputs=[output_image, gr.File(label="Download as PNG")],
88
  )
89
 
 
 
 
90
  if __name__ == "__main__":
91
  interface.launch(debug=True)