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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -44,7 +44,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, output_buffer # Return image and buffer for download
48
 
49
  # Gradio Interface
50
  with gr.Blocks(title="Sticker Maker") as interface:
@@ -59,7 +59,6 @@ with gr.Blocks(title="Sticker Maker") as interface:
59
  label="Outline Thickness", minimum=0, maximum=20, value=5, step=1
60
  )
61
  outline_color = gr.ColorPicker(label="Outline Color", value="#FFFFFF")
62
- create_btn = gr.Button("Create Sticker", variant="primary")
63
 
64
  with gr.Column():
65
  output_image = gr.Image(
@@ -73,18 +72,20 @@ with gr.Blocks(title="Sticker Maker") as interface:
73
  outputs=[outline_size, outline_color],
74
  )
75
 
76
- # Process image and allow direct download from preview pane
 
 
 
 
 
77
  create_btn.click(
78
- fn=lambda *args: process_image(*args)[0],
79
  inputs=[image_upload, outline_size, outline_color, add_outline],
80
  outputs=output_image,
81
  )
82
 
83
- output_image.change(
84
- fn=lambda img: process_image(img, outline_size=0, outline_color="#FFFFFF", add_outline=False)[1],
85
- inputs=output_image,
86
- outputs=gr.File(label="Download Sticker as PNG"),
87
- )
88
 
89
  if __name__ == "__main__":
90
  interface.launch(debug=True)
 
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:
 
59
  label="Outline Thickness", minimum=0, maximum=20, value=5, step=1
60
  )
61
  outline_color = gr.ColorPicker(label="Outline Color", value="#FFFFFF")
 
62
 
63
  with gr.Column():
64
  output_image = gr.Image(
 
72
  outputs=[outline_size, outline_color],
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)