image-upscaler / app.py
elseodelasgalletas's picture
Create app.py
57007fd verified
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gradio as gr
from PIL import Image, ImageEnhance
def function(image, size):
w, h = int(image.size[0] * int(size[1:])), int(image.size[1] * int(size[1:]))
enhancer = ImageEnhance.Color(image)
image = enhancer.enhance(0.75)
enhancer = ImageEnhance.Contrast(image)
image = enhancer.enhance(1.25)
enhancer = ImageEnhance.Sharpness(image)
image = enhancer.enhance(1.25)
image = image.resize((w, h), resample=Image.Resampling.LANCZOS)
return image
with gr.Blocks() as interface:
with gr.Tab("Image Upscaler And Enhancer"):
with gr.Row():
with gr.Column(scale=3):
out = gr.Image(
label='This is a temporary image, right click to download.',
show_download_button=True,
show_share_button=False,
scale=2,
type='pil'
)
with gr.Column(scale=1):
with gr.Tab("Settings"):
size = gr.Radio(
label='Size',
choices=['x2', 'x4'],
value='x2'
)
b = gr.Button('Upscale & Enhance')
b.click(fn=function, inputs=[out, size], outputs=out)
interface.launch()