afondiel's picture
add app files
0a07ad3
raw
history blame
No virus
1.64 kB
import gradio as gr
from gradio_imageslider import ImageSlider
import numpy as np
import torch
import fastai
from deoldify import device
from deoldify.device_id import DeviceId
from deoldify.visualize import *
import warnings
from collections.abc import Sized # Import Sized from collections.abc
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
# Set the device to use for computation
# choices: CPU, GPU0...GPU7
if torch.cuda.is_available():
device.set(device=DeviceId.GPU0)
else:
device.set(device=DeviceId.CPU)
# Load the pre-trained model
colorizer = get_image_colorizer(artistic=True)
def colorizer_fn(input_img, render_factor):
"""
Colorize grayscale images/photos
- @param input_img old (grayscale) image
- @param render_factor render_factor
"""
if input_img is not None and input_img !='':
output_img = colorizer.get_transformed_image(
path=input_img,
render_factor=int(render_factor),
watermarked=watermarked,
post_process=True,
)
else:
print('Provide an image and try again.')
return (input_img, output_img) # Return a tuple of old and color Image to be plotted with ImageSlider()
title = "AI Image Colorizer"
description = "Colorize old images with AI"
examples = [["./demo.jpg"],]
demo = gr.Interface(
fn=colorizer_fn,
inputs=[gr.Image(type="filepath" , label="Old image"), gr.Slider(0, 40, label="Render Factor", value=10)],
outputs=ImageSlider(type="pil", label="Old vs Colored image"),
examples=examples,
title=title,
description=description,
)
# Launch the demo
demo.launch()