File size: 1,669 Bytes
ca4d175 2606f8b ca4d175 |
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 |
import gradio as gr
from PIL import Image, PngImagePlugin
import numpy as np
import os
os.system("chmod +x models/waifu2x-ncnn-vulkan")
noisedict = {
"なし": -1,
"低": 0,
"中": 1,
"高": 2,
"最高": 3
}
scaledict = {
"1倍": 1,
"2倍": 2,
}
formatdict = {
"PNG": "png",
"JPG": "jpg",
"WebP": "webp"
}
def response_greet(image, noise, scale, format):
info = image.info
n = noisedict[noise]
s = scaledict[scale]
f = formatdict[format]
image.save("input.png")
os.system(f"models/waifu2x-ncnn-vulkan -i input.png -o output.{f} -n {n} -s {s} -f {f} -g -1")
image = Image.open(f"output.{f}")
image.info = info
return image
with gr.Blocks() as app:
gr.Markdown("## Waifu2x with png metadata demo")
with gr.Row():
with gr.Column():
image = gr.Image(label="入力画像", interactive=True, type="pil", )
noise = gr.Radio(choices=["なし", "低", "中", "高", "最高"], label="ノイズ除去", value="中", interactive=True, type="value"),
scale = gr.Radio(choices=["1倍", "2倍"], label="拡大", value="2倍", interactive=True, type="value"),
format = gr.Radio(choices=["PNG", "JPG", "WebP"], label="出力フォーマット(※現時点ではPNGのみ選択できます)", value="PNG", type="value"),
button = gr.Button("送信")
with gr.Column():
output = gr.Image(label="出力画像", type="pil")
button.click(fn=response_greet, inputs=[image, noise[0], scale[0], format[0]], outputs=output, api_name="Waifu2xで画像をアップコンバートします。")
app.launch() |