Mehedi258456's picture
requirements.txt
7a156f5 verified
raw
history blame contribute delete
898 Bytes
import gradio as gr
from PIL import Image
from rembg import remove
import io
def upscale_and_remove_bg(image, scale):
# Step 1: Upscale
width, height = image.size
new_width = int(width * scale)
new_height = int(height * scale)
upscaled = image.resize((new_width, new_height), Image.BICUBIC)
# Step 2: Remove Background
transparent = remove(upscaled)
# Step 3: Convert to PNG
with io.BytesIO() as output:
transparent.save(output, format="PNG")
output.seek(0)
return output.read()
gr.Interface(
fn=upscale_and_remove_bg,
inputs=[
gr.Image(type="pil"),
gr.Radio([2, 4, 8], label="Upscale (2x / 4x / 8x)")
],
outputs=gr.File(label="Download PNG"),
title="AI Image Upscaler + Background Remover",
description="Upload an image, upscale it, remove background, and download transparent PNG."
).launch()