Update app.py
Browse files1234567891011import gradio as grfrom rembg import removefrom PIL import Imagedef remove_background(image):img = image.convert("RGBA")output = remove(img)return outputiface = gr.Interface(fn=remove_background, inputs=gr.Image(type="pil"), outputs=gr.Image(type="pil"))iface.launch()1234567891011121314151617181920212223242526272829303132import gradio as grfrom rembg import removefrom PIL import Imageimport iodef remove_background(image):"""Remove background from an input PIL image and return a transparent PNG."""# Convert PIL to bytesbyte_arr = io.BytesIO()image.save(byte_arr, format="PNG")input_bytes = byte_arr.getvalue()# Run background removeroutput_bytes = remove(input_bytes)# Convert back to PILoutput = Image.open(io.BytesIO(output_bytes)).convert("RGBA")return output# Gradio interfaceiface = gr.Interface(fn=remove_background,inputs=gr.Image(type="pil", label="Upload Image"),outputs=gr.Image(type="pil", label="Background Removed"),title="Background Remover",description="Upload an image and remove its background using rembg",api_name="predict" # 👈 this is your API endpoint)iface.launch(show_error=True) # show_error=True helps debugging
app.py+25-4