Spaces:
Running
Running
File size: 8,432 Bytes
680cb9b 2690ff3 4704ee6 2cea673 4704ee6 b8ea3b0 4704ee6 b8ea3b0 4704ee6 b8ea3b0 6004c63 b8ea3b0 4704ee6 b8ea3b0 4704ee6 5551a41 06521e0 5551a41 1b5194e 680cb9b 4704ee6 fa6733b 4704ee6 3aacce3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
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"""<center>An automatic colorization functionality for Real-Time User-Guided Image Colorization with Learned Deep Priors,ECCV16 & SIGGRAPH 2017 Models!<br>
Practically the algorithm is used to COLORIZE your **old BLACK & WHITE / GRAYSCALE photos**.<br>
To use it, simply just upload the concerned image.<br>
"""
article = r"""
<p style='text-align: '> 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. </p>
<img src="https://camo.githubusercontent.com/8f849fd53753e61659664d37849703d949209ec93957d1a2fd529be9772f7030/687474703a2f2f726963687a68616e672e6769746875622e696f2f636f6c6f72697a6174696f6e2f7265736f75726365732f696d616765732f746561736572342e6a7067" alt="Teaser Image" data-canonical-src="http://richzhang.github.io/colorization/resources/images/teaser4.jpg" style="max-width: 100%;">
<p>
<img class="round" style="height:275px" src="http://richzhang.github.io/colorization/resources/images/net_diagram.jpg">
</p>
<div class="footer">
<p>Built by <a href="" style="text-decoration: underline;" target="_blank">Dushyantsinh Jadeja</a> & the Model being used in here is from <a href="https://github.com/richzhang/colorization" style="text-decoration: underline;" target="_blank">richzhang</a> - Gradio Demo by π€ Hugging Face </p>
</div>
<div class="acknowledgments">
<p>
<h4>LICENSE</h4>
</p>
<h3 class="mt-0 mb-2 h4">BSD 2-Clause "Simplified" License</h3>
<h4 class="mt-1 mb-2 h5">Permissions</h4>
<ul class="list-style-none">
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-check color-fg-success ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path>
</svg>
<span class="v-align-middle" title="The licensed material and derivatives may be used for commercial purposes."> Commercial use </span>
</li>
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-check color-fg-success ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path>
</svg>
<span class="v-align-middle" title="The licensed material may be modified."> Modification </span>
</li>
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-check color-fg-success ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path>
</svg>
<span class="v-align-middle" title="The licensed material may be distributed."> Distribution </span>
</li>
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-check color-fg-success ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path>
</svg>
<span class="v-align-middle" title="The licensed material may be used and modified in private."> Private use </span>
</li>
</ul>
<h4 class="mt-1 mb-2 h5">Limitations</h4>
<ul class="list-style-none">
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-x color-fg-danger ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"></path>
</svg>
<span class="v-align-middle" title="This license includes a limitation of liability."> Liability </span>
</li>
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-x color-fg-danger ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"></path>
</svg>
<span class="v-align-middle" title="This license explicitly states that it does NOT provide any warranty."> Warranty </span>
</li>
</ul>
<h4 class="mt-1 mb-2 h5">Conditions</h4>
<ul class="list-style-none">
<li class="text-small pl-3">
<svg width="13" class="octicon octicon-info color-fg-accent ml-n3 v-align-middle" viewBox="0 0 16 16" version="1.1" height="13" aria-hidden="true">
<path fill-rule="evenodd" d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg>
<span class="v-align-middle" title="A copy of the license and copyright notice must be included with the licensed material."> License and copyright notice </span>
</li>
</ul>
</div> For the full list of restrictions please <a href="https://github.dev/richzhang/colorization/blob/master/LICENSE" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a>
</p>
<br>
<center>
<img src='https://visitor-badge.glitch.me/badge?page_id=dj_colorization_eccv16siggraph17' alt='visitor badge'>
</center>
"""
#with gr.Interface(css=css) as mainBody:
gr.HTML("""<style>""" + css+ """</Style>""")
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")
],
#inputs="sketchpad",
#outputs="label",
theme="huggingface",
title=title,
description=description,
article=article,
live=True,
)
mainBody.launch() |