resoBoost / app.py
oshanmodi's picture
modified app interface, removed scale input.
200353d
Raw History Blame Contribute Delete
1.69 kB
import gradio as gr
from cv2 import dnn_superres
from pathlib import Path
def upscale_image(img, model):
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read image
image = img
# return model
# Read the desired model
if model == 'Slow, high quality':
model = 'EDSR_x4'
scale = 4
else:
model = 'FSRCNN_small_x2'
scale = 2
path = f"models/{model}.pb"
if not Path(path).exists():
raise FileNotFoundError
sr.readModel(path)
model_architecture = model.split("_")[0].lower()
# Set the desired model and scale to get correct pre- and post-processing
sr.setModel(model_architecture, scale)
# Upscale the image
result = sr.upsample(image)
return result
# Save the image
# cv2.imwrite("./upscaledx4.png", result)
input_image = gr.Image( label = "Browse/drop image to upscale:")
input_model = gr.Radio(['Quick and efficient','Slow, high quality'], value = 'Quick and efficient',label = 'Select method:',)
# input_multiplier = gr.Slider(1, 4, value = 2, step = 1, label = 'Scale up by:')
inputs = [input_image, input_model]
output_image = gr.Image(height=300, width = 450, invert_colors=False)
outputs = [output_image]
iface = gr.Interface(fn=upscale_image,
inputs=inputs,
outputs=output_image,
allow_flagging='never',
title='betterImage',
description="If you are wondering how to improve the resolution of your image, then this free tool is perfect for you. Our service uses AI to upscale image files.")
iface.launch()