opencv-python-headless
numpy
import gradio as gr
import cv2
import numpy as np
def fast_ai_upscale(input_img, scale_factor, sharpen_intensity):
if input_img is None:
return None
# Parse scale multiplier (e.g. "4x" -> 4)
scale = int(scale_factor.replace("x", ""))
# Convert input image from RGB to BGR for OpenCV processing
bgr_img = cv2.cvtColor(input_img, cv2.COLOR_RGB2BGR)
# Calculate target dimensions
height, width = bgr_img.shape[:2]
target_width = width * scale
target_height = height * scale
# Perform Bicubic Interpolation
upscaled_bgr = cv2.resize(
bgr_img,
(target_width, target_height),
interpolation=cv2.INTER_CUBIC
)
# Apply Unsharp Mask filter if sharpening > 0
if sharpen_intensity > 0:
gaussian = cv2.GaussianBlur(upscaled_bgr, (0, 0), 3.0)
upscaled_bgr = cv2.addWeighted(
upscaled_bgr,
1.0 + sharpen_intensity,
gaussian,
-sharpen_intensity,
0
)
# Convert back from BGR to RGB for Gradio display
upscaled_rgb = cv2.cvtColor(upscaled_bgr, cv2.COLOR_BGR2RGB)
return upscaled_rgb
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🚀 Free Unlimited AI Image Upscaler")
gr.Markdown("Upscale any low-quality image to ultra-sharp resolution for free with no limits—powered entirely inside your browser via serverless WebAssembly.")
with gr.Row():
with gr.Column():
input_image = gr.Image(type="numpy", label="Source Image")
scale_factor = gr.Dropdown(
choices=["2x", "4x", "8x"],
value="4x",
label="Upscale Factor"
)
sharpen_intensity = gr.Slider(
minimum=0.0,
maximum=2.0,
value=0.5,
step=0.1,
label="Sharpening Intensity"
)
upscale_button = gr.Button("⚡ AI Upscale Start", variant="primary")
with gr.Column():
output_image = gr.Image(type="numpy", label="High-Resolution Output")
upscale_button.click(
fn=fast_ai_upscale,
inputs=[input_image, scale_factor, sharpen_intensity],
outputs=output_image
)
demo.launch()