Spaces:
Running
Running
Update app.py
Browse files1 unmodified line234567836 unmodified lines4546474849501 unmodified linefrom PIL import Imageimport rembgimport ioimport tempfiledef process_image(image, outline_size, outline_color, add_outline):if image is None:36 unmodified linesfinal_img.save(output_buffer, format="PNG")output_buffer.seek(0)return final_img, output_buffer# Gradio Interface1 unmodified line23456736 unmodified lines44454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051 unmodified linefrom PIL import Imageimport rembgimport iodef process_image(image, outline_size, outline_color, add_outline):if image is None:36 unmodified linesfinal_img.save(output_buffer, format="PNG")output_buffer.seek(0)return final_img# Gradio Interfacewith gr.Blocks(title="Sticker Maker") as interface:gr.Markdown("# Sticker Maker")gr.Markdown("Upload an image to remove the background and optionally add an outline.")with gr.Row():with gr.Column():image_upload = gr.Image(label="Upload Image", type="pil")add_outline = gr.Checkbox(label="Add Outline", value=True)outline_size = gr.Slider(label="Outline Thickness", minimum=0, maximum=20, value=5, step=1)outline_color = gr.ColorPicker(label="Outline Color", value="#FFFFFF")with gr.Column():output_image = gr.Image(label="Preview and Download", type="pil", interactive=False)# Show/hide outline options based on checkboxadd_outline.change(fn=lambda x: gr.update(visible=x),inputs=add_outline,outputs=[outline_size, outline_color],)# Process image and show result in the preview panedef 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 previewcreate_btn = gr.Button("Create Sticker", variant="primary")create_btn.click(fn=process_and_return,inputs=[image_upload, outline_size, outline_color, add_outline],outputs=output_image,)# Enable PNG download directly from the preview paneoutput_image.download(label="Download Sticker as PNG")if __name__ == "__main__":interface.launch(debug=True)# Paste the processed image onto the backgroundbackground.paste(processed_img, (outline_size, outline_size), processed_img)final_img = backgroundelse:final_img = processed_img# Save the result as bytes for Gradiooutput_buffer = io.BytesIO()final_img.save(output_buffer, format="PNG")output_buffer.seek(0)return final_img, output_buffer# Gradio Interface
app.py+56-1