Spaces:
Runtime error
Runtime error
Improvements?
Browse files
app.py
CHANGED
@@ -19,21 +19,30 @@ def inference(img, size, type):
|
|
19 |
_id = randint(1, 10000)
|
20 |
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
|
21 |
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
|
22 |
-
|
23 |
-
|
24 |
-
run_cmd("
|
25 |
-
run_cmd("
|
|
|
|
|
26 |
img.save(INPUT_DIR + "1.jpg", "JPEG")
|
27 |
|
28 |
if type == "Manga v2":
|
29 |
-
run_cmd("python inference_manga_v2.py
|
30 |
else:
|
31 |
-
run_cmd("python inference.py
|
32 |
|
33 |
-
img_out = Image.open(
|
34 |
|
35 |
if size == "x2":
|
36 |
-
img_out = img_out.resize((
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
return [img_out]
|
39 |
|
@@ -48,4 +57,5 @@ demo = gr.Interface(
|
|
48 |
outputs=[output_image]
|
49 |
)
|
50 |
|
|
|
51 |
demo.launch(debug=is_colab, share=is_colab, inline=is_colab)
|
|
|
19 |
_id = randint(1, 10000)
|
20 |
INPUT_DIR = "/tmp/input_image" + str(_id) + "/"
|
21 |
OUTPUT_DIR = "/tmp/output_image" + str(_id) + "/"
|
22 |
+
img_in_path = os.path.join(INPUT_DIR, "1.jpg")
|
23 |
+
img_out_path = os.path.join(OUTPUT_DIR, "1_out.jpg")
|
24 |
+
run_cmd(f"rm -rf {INPUT_DIR}")
|
25 |
+
run_cmd(f"rm -rf {OUTPUT_DIR}")
|
26 |
+
run_cmd(f"mkdir {INPUT_DIR}")
|
27 |
+
run_cmd(f"mkdir {OUTPUT_DIR}")
|
28 |
img.save(INPUT_DIR + "1.jpg", "JPEG")
|
29 |
|
30 |
if type == "Manga v2":
|
31 |
+
run_cmd(f"python inference_manga_v2.py {img_in_path} {img_out_path}")
|
32 |
else:
|
33 |
+
run_cmd(f"python inference.py {img_in_path} {img_out_path} {type}")
|
34 |
|
35 |
+
img_out = Image.open(img_out_path)
|
36 |
|
37 |
if size == "x2":
|
38 |
+
img_out = img_out.resize((img_out.width // 2, img_out.height // 2), resample=Image.BICUBIC)
|
39 |
+
|
40 |
+
img_out.save(img_out_path, optimize=True) # Add more optimizations
|
41 |
+
img_out = Image.open(img_out_path)
|
42 |
+
|
43 |
+
# Remove input and output image
|
44 |
+
run_cmd(f"rm -f {img_in_path}")
|
45 |
+
run_cmd(f"rm -f {img_out_path}")
|
46 |
|
47 |
return [img_out]
|
48 |
|
|
|
57 |
outputs=[output_image]
|
58 |
)
|
59 |
|
60 |
+
demo.queue()
|
61 |
demo.launch(debug=is_colab, share=is_colab, inline=is_colab)
|