Spaces:
Running
Running
Update app.py
Browse files1 unmodified line234567836 unmodified lines454647474849505111 unmodified lines63646565666768694 unmodified lines74757676777877787980818283848285868487888987888990911 unmodified linefrom PIL import Imageimport rembgimport ioimport tempfile
def process_image(image, outline_size, outline_color, add_outline): if image is None:36 unmodified lines final_img.save(output_buffer, format="PNG") output_buffer.seek(0)
return final_img return final_img, output_buffer
# Gradio Interfacewith gr.Blocks(title="Sticker Maker") as interface:11 unmodified lines
with gr.Column(): output_image = gr.Image( label="Preview and Download", type="pil", interactive=False label="Preview", type="pil", interactive=False )
# Show/hide outline options based on checkbox4 unmodified lines )
# Process image and show result in the preview pane def process_and_return(image, outline_size, outline_color, add_outline): processed_image = process_image(image, outline_size, outline_color, add_outline) return processed_image # Return processed image for preview def process_and_download(image, outline_size, outline_color, add_outline): processed_image, output_buffer = process_image(image, outline_size, outline_color, add_outline) # Return the processed image for preview and the PNG file for download return processed_image, output_buffer
# Add button to process image and provide preview create_btn = gr.Button("Create Sticker", variant="primary") create_btn.click( fn=process_and_return, fn=process_and_download, inputs=[image_upload, outline_size, outline_color, add_outline], outputs=output_image, outputs=[output_image, gr.File(label="Download as PNG")], )
# Enable PNG download directly from the preview pane output_image.download(label="Download Sticker as PNG")
if __name__ == "__main__": interface.launch(debug=True)app.py+10-10