import gradio as gr import numpy as np import colorizers as c from colorizers.util import postprocess_tens, preprocess_img def interface(image, model: str = "eccv16"): if model == "eccv16": img = c.eccv16(pretrained=True).eval() else: img = c.siggraph17(pretrained=True).eval() oimg = np.asarray(image) if(oimg.ndim == 2): oimg = np.tile(oimg[:,:,None], 3) (tens_l_orig, tens_l_rs) = preprocess_img(oimg) output_img = postprocess_tens( tens_l_orig, img(tens_l_rs).cpu() ) return output_img css=''' .Box { background-color: var(--color-canvas-default); border-color: var(--color-border-default); border-style: solid; border-width: 1px; border-radius: 6px; } .d-flex { display: flex !important; } .flex-md-row { flex-direction: row !important; } .flex-column { flex-direction: column !important; } ''' title = "Image Colorization Using AI Models" description = r"""
An automatic colorization functionality for Real-Time User-Guided Image Colorization with Learned Deep Priors,ECCV16 & SIGGRAPH 2017 Models!
Practically the algorithm is used to COLORIZE your **old BLACK & WHITE / GRAYSCALE photos**.
To use it, simply just upload the concerned image.
""" article = r"""

Given a grayscale photograph as input, this demo attacks the problem of hallucinating a plausible color version of the photograph. This problem is clearly underconstrained, so previous approaches have either relied on significant user interaction or resulted in desaturated colorizations. A fully automatic approach has been proposed that produces vibrant and realistic colorizations. The underlying uncertainty of the problem was embraced by posing it as a classification task and use class-rebalancing at training time to increase the diversity of colors in the result. The system is implemented as a feed-forward pass in a CNN at test time and is trained on over a million color images. The algorithm is evaluated using a "colorization Turing test," asking human participants to choose between a generated and ground truth color image. The method used here successfully fools humans on 32% of the trials, significantly higher than other methodology used by the other photo automation tools. Moreover, the colorization can be a powerful pretext task for self-supervised feature learning, acting as a cross-channel encoder. This approach results in state-of-the-art performance on several feature learning benchmarks.

Teaser Image

LICENSE

richzhang/colorization is licensed under the

BSD 2-Clause "Simplified" License

A permissive license that comes in two variants, the BSD 2-Clause and BSD 3-Clause. Both have very minute differences to the MIT license.

Permissions

  • Commercial use
  • Modification
  • Distribution
  • Private use

Limitations

  • Liability
  • Warranty

Conditions

  • License and copyright notice

This is not legal advice. Learn more about repository licenses.

For the full list of restrictions please read the license


visitor badge
""" mainBody = gr.Blocks(css=css) #with gr.Blocks(css=".gradio-container {background-color: red}") as demo: mainBody = gr.Interface( interface, [ gr.components.Image(type="pil", label="image"), gr.components.Radio( ["eccv16", "siggraph17"], type="value", label="model" ) ], [ gr.components.Image(label="output") ], css=css, #inputs="sketchpad", #outputs="label", theme="huggingface", title=title, description=description, article=article, live=True, ) mainBody.launch()