Update
Browse files
app.py
CHANGED
@@ -8,32 +8,31 @@ import shlex
|
|
8 |
import subprocess
|
9 |
|
10 |
import gradio as gr
|
|
|
11 |
|
12 |
from app_colorization import create_demo as create_demo_colorization
|
13 |
from app_superresolution import create_demo as create_demo_superresolution
|
14 |
|
15 |
-
DESCRIPTION = '
|
16 |
|
17 |
-
This is an unofficial demo for [https://github.com/wyhuai/DDNM/tree/main/hq_demo](https://github.com/wyhuai/DDNM/tree/main/hq_demo).
|
18 |
-
'''
|
19 |
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
20 |
-
DESCRIPTION += f'
|
21 |
-
|
22 |
-
|
23 |
-
<p
|
24 |
-
''
|
25 |
-
|
26 |
-
MODEL_DIR
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
with gr.Blocks(css='style.css') as demo:
|
39 |
gr.Markdown(DESCRIPTION)
|
@@ -42,4 +41,4 @@ with gr.Blocks(css='style.css') as demo:
|
|
42 |
create_demo_superresolution()
|
43 |
with gr.TabItem(label='Colorization'):
|
44 |
create_demo_colorization()
|
45 |
-
demo.queue(
|
|
|
8 |
import subprocess
|
9 |
|
10 |
import gradio as gr
|
11 |
+
import torch
|
12 |
|
13 |
from app_colorization import create_demo as create_demo_colorization
|
14 |
from app_superresolution import create_demo as create_demo_superresolution
|
15 |
|
16 |
+
DESCRIPTION = '# [DDNM-HQ](https://github.com/wyhuai/DDNM/tree/main/hq_demo)'
|
17 |
|
|
|
|
|
18 |
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
19 |
+
DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
20 |
+
|
21 |
+
if torch.cuda.is_available():
|
22 |
+
DESCRIPTION += '\n<p>Running on GPU 🔥</p>'
|
23 |
+
MODEL_DIR = pathlib.Path('DDNM/hq_demo/data/pretrained')
|
24 |
+
if not MODEL_DIR.exists():
|
25 |
+
MODEL_DIR.mkdir()
|
26 |
+
subprocess.run(shlex.split(
|
27 |
+
'wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_classifier.pt'
|
28 |
+
),
|
29 |
+
cwd=MODEL_DIR.as_posix())
|
30 |
+
subprocess.run(shlex.split(
|
31 |
+
'wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/256x256_diffusion.pt'
|
32 |
+
),
|
33 |
+
cwd=MODEL_DIR.as_posix())
|
34 |
+
else:
|
35 |
+
DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.'
|
36 |
|
37 |
with gr.Blocks(css='style.css') as demo:
|
38 |
gr.Markdown(DESCRIPTION)
|
|
|
41 |
create_demo_superresolution()
|
42 |
with gr.TabItem(label='Colorization'):
|
43 |
create_demo_colorization()
|
44 |
+
demo.queue(api_open=False, max_size=5).launch()
|