File size: 1,904 Bytes
b8d9f69 115ddf5 b8d9f69 d9db1f6 115ddf5 d9db1f6 115ddf5 d9db1f6 b8d9f69 115ddf5 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 115ddf5 b8d9f69 d9db1f6 b8d9f69 d9db1f6 b8d9f69 |
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 |
#!/usr/bin/env python
import json
import pathlib
import shlex
import subprocess
import gradio as gr
def run(image_path: str, class_index: int, sigma_y: float) -> str:
out_name = image_path.split("/")[-1].split(".")[0]
subprocess.run( # noqa: S603
shlex.split(
f"python main.py --config confs/inet256.yml --deg colorization --scale 1 --class {class_index} --path_y {image_path} --save_path {out_name} --sigma_y {sigma_y}"
),
cwd="DDNM/hq_demo",
check=False,
)
return f"DDNM/hq_demo/results/{out_name}/final/00000.png"
def create_demo() -> gr.Blocks:
examples = [
[
"sample_images/monarch_gray.png",
"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",
0,
],
[
"sample_images/tiger_gray.png",
"tiger, Panthera tigris",
0,
],
]
with pathlib.Path("imagenet_classes.json").open() as f:
imagenet_class_names = json.load(f)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
image = gr.Image(label="Input image", type="filepath")
class_index = gr.Dropdown(label="Class name", choices=imagenet_class_names, type="index", value=950)
sigma_y = gr.Number(label="sigma_y", value=0, precision=2)
run_button = gr.Button("Run")
with gr.Column():
result = gr.Image(label="Result", type="filepath")
gr.Examples(
examples=examples,
inputs=[
image,
class_index,
sigma_y,
],
)
run_button.click(
fn=run,
inputs=[
image,
class_index,
sigma_y,
],
outputs=result,
)
return demo
|