File size: 1,532 Bytes
b43e10d
ceac432
6887d0a
44a0fda
 
 
7abfb9e
ceac432
6887d0a
 
44a0fda
 
 
 
 
 
 
ceac432
02a3bed
44a0fda
01d839a
44a0fda
01d839a
 
 
 
1c6d57c
7618b15
3cb6ee0
 
02a3bed
3cb6ee0
 
b43e10d
58ba404
02a3bed
 
d317fe8
44a0fda
6887d0a
44a0fda
3cb6ee0
b43e10d
6887d0a
 
8d22ff6
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
import os
import gradio as gr
import util
from random import randint
import sys
from subprocess import call
from PIL import Image

is_colab = util.is_google_colab()

def run_cmd(command):
    try:
        print(command)
        call(command, shell=True)
    except KeyboardInterrupt:
        print("Process interrupted")
        sys.exit(1)

def inference(img, size, type):
    _id = randint(1, 10000)
    INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
    OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
    run_cmd("rm -rf " + INPUT_DIR)
    run_cmd("rm -rf " + OUTPUT_DIR)
    run_cmd("mkdir " + INPUT_DIR)
    run_cmd("mkdir " + OUTPUT_DIR)
    img.save(INPUT_DIR + "1.jpg", "JPEG")

    run_cmd("python inference_manga.py "+ os.path.join(INPUT_DIR, "1.jpg") + " " + os.path.join(OUTPUT_DIR, "1_out.jpg"))
    img_out = Image.open(os.path.join(OUTPUT_DIR, "1_out.jpg"))
    if size is "x2":
        img_out = img_out.resize((s//2 for s in img_out.size))
    return [img_out]

input_image = gr.Image(type="pil", label="Input")
upscale_type = gr.Radio(["Manga", "Anime", "General"], label="Select the type of picture you want to upscale:", value="Manga")
upscale_size = gr.Radio(["x4", "x2"], label="Upscale by:", value="x4")
output_image = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")

demo = gr.Interface(
    inference,
    inputs=[input_image, upscale_size, upscale_type],
    outputs=[output_image]
)

demo.launch(debug=is_colab, share=is_colab, inline=is_colab)