Spaces:
Running
Running
Update app.py
Browse files1 unmodified line234567831 unmodified lines4041424344454647484950515253545514 unmodified lines707172737475762 unmodified lines7980818283848586878889909192939495961 unmodified linefrom PIL import Imageimport rembgimport ioimport tempfiledef process_image(image, outline_size, outline_color, add_outline):if image is None:31 unmodified lineselse:final_img = processed_imgreturn final_img# Handle downloaddef download_sticker(image):if image:# Save image to a temporary filetemp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")image.save(temp_file.name, format="PNG")temp_file.close()return temp_file.name # Return the file path# Gradio Interfacewith gr.Blocks(title="Sticker Maker") as interface:14 unmodified linesoutput_image = gr.Image(label="Preview and Download", type="pil", interactive=False)download_btn = gr.Button("Download Sticker", variant="secondary")# Show/hide outline options based on checkboxadd_outline.change(2 unmodified linesoutputs=[outline_size, outline_color],)# Process image and show resultcreate_btn.click(fn=process_image,inputs=[image_upload, outline_size, outline_color, add_outline],outputs=output_image,)# Enable download functionalitydownload_btn.click(fn=download_sticker,inputs=output_image,outputs=gr.File(label="Sticker.png"),)if __name__ == "__main__":1 unmodified line23456731 unmodified lines39404142434445464748495014 unmodified lines6566676869702 unmodified lines73747576777879808182838485868788891 unmodified linefrom PIL import Imageimport rembgimport iodef process_image(image, outline_size, outline_color, add_outline):if image is None:31 unmodified lineselse: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 # Return image and buffer for download# Gradio Interfacewith gr.Blocks(title="Sticker Maker") as interface:14 unmodified linesoutput_image = gr.Image(label="Preview and Download", type="pil", interactive=False)# Show/hide outline options based on checkboxadd_outline.change(2 unmodified linesoutputs=[outline_size, outline_color],)# Process image and allow direct download from preview panecreate_btn.click(fn=lambda *args: process_image(*args)[0],inputs=[image_upload, outline_size, outline_color, add_outline],outputs=output_image,)output_image.change(fn=lambda img: process_image(img, outline_size=0, outline_color="#FFFFFF", add_outline=False)[1],inputs=output_image,outputs=gr.File(label="Download Sticker as PNG"),)if __name__ == "__main__":
app.py+10-17