iupztx / app.py
Geek7's picture
Update app.py
588519c verified
import gradio as gr
import cv2
import numpy as np
from PIL import Image
# Function to upscale the image
def upscale_image(input_image, upscale_factor):
# Convert the uploaded image to an OpenCV format
input_image = np.array(input_image)
# Perform upscaling using OpenCV's resize function
output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC)
return Image.fromarray(output_image)
# Function to handle the Gradio interface
def process_image(image, upscale_factor):
# Convert the uploaded image and upscale it
upscaled_image = upscale_image(image, upscale_factor)
# Return the upscaled image
return upscaled_image
# Gradio interface definition
demo = gr.Interface(
fn=process_image,
inputs=[gr.Image(type="pil",sources=["upload","webcam"]), gr.Slider(2, 10, step=2, label="Upscale Factor")],
outputs=gr.Image(type="pil",show_share_button=False,show_fullscreen_button=False),
title="Image Upscaler",
description="Upload an image and select an upscale factor to upscale your image.",
css="footer {visibility: hidden}"
)
# Launch the Gradio app
demo.launch()