|
import os |
|
os.system("hub install deoldify==1.0.1") |
|
import gradio as gr |
|
import paddlehub as hub |
|
from pathlib import Path |
|
from datetime import datetime |
|
from typing import Optional |
|
|
|
|
|
model = hub.Module(name='deoldify') |
|
|
|
render_factor=35 |
|
|
|
|
|
def colorize_image(image): |
|
|
|
if not os.path.exists("./output"): |
|
os.makedirs("./output") |
|
|
|
|
|
model.predict(image.name) |
|
return './output/DeOldify/'+Path(image.name).stem+".png" |
|
|
|
|
|
def create_interface(): |
|
with gr.Blocks() as enhancer: |
|
gr.Markdown("Colorize old black & white photos") |
|
with gr.Column(scale=1, label = "Colorize photo", visible=True) as colorize_column: |
|
colorize_input = gr.Image(type="file") |
|
colorize_button = gr.Button("Colorize!") |
|
colorize_output = gr.Image(type="file") |
|
download_colorize_button = gr.outputs.File(label="Download colorized image!") |
|
colorize_button.click(colorize_image, inputs=colorize_input, outputs=colorize_output) |
|
enhancer.launch() |
|
|
|
def run_code(): |
|
create_interface() |
|
|
|
|
|
run_code() |