Spaces:
Running
Running
Update
Browse files- app.py +18 -20
- app_generated_image.py +2 -1
- app_real_image.py +2 -1
app.py
CHANGED
@@ -8,30 +8,29 @@ import shlex
|
|
8 |
import subprocess
|
9 |
|
10 |
import gradio as gr
|
|
|
11 |
|
12 |
from app_generated_image import create_prompt_demo
|
13 |
from app_real_image import create_real_image_demo
|
14 |
|
15 |
-
DESCRIPTION = '
|
16 |
-
|
17 |
-
This is an unofficial demo for [https://github.com/MichalGeyer/plug-and-play](https://github.com/MichalGeyer/plug-and-play).
|
18 |
-
'''
|
19 |
|
20 |
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
21 |
-
DESCRIPTION += f'
|
22 |
-
|
23 |
-
|
24 |
-
<p
|
25 |
-
''
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
with gr.Blocks(css='style.css') as demo:
|
37 |
gr.Markdown(DESCRIPTION)
|
@@ -40,5 +39,4 @@ with gr.Blocks(css='style.css') as demo:
|
|
40 |
create_real_image_demo()
|
41 |
with gr.TabItem('Use prompt as input'):
|
42 |
create_prompt_demo()
|
43 |
-
|
44 |
-
demo.queue().launch()
|
|
|
8 |
import subprocess
|
9 |
|
10 |
import gradio as gr
|
11 |
+
import torch
|
12 |
|
13 |
from app_generated_image import create_prompt_demo
|
14 |
from app_real_image import create_real_image_demo
|
15 |
|
16 |
+
DESCRIPTION = '# [Plug-and-Play diffusion features](https://github.com/MichalGeyer/plug-and-play)'
|
|
|
|
|
|
|
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 |
+
weight_dir = pathlib.Path('plug-and-play/models/ldm/stable-diffusion-v1')
|
24 |
+
if not weight_dir.exists():
|
25 |
+
subprocess.run(
|
26 |
+
shlex.split(
|
27 |
+
'mkdir -p plug-and-play/models/ldm/stable-diffusion-v1/'))
|
28 |
+
subprocess.run(
|
29 |
+
shlex.split(
|
30 |
+
'wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt -O plug-and-play/models/ldm/stable-diffusion-v1/model.ckpt'
|
31 |
+
))
|
32 |
+
else:
|
33 |
+
DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.'
|
34 |
|
35 |
with gr.Blocks(css='style.css') as demo:
|
36 |
gr.Markdown(DESCRIPTION)
|
|
|
39 |
create_real_image_demo()
|
40 |
with gr.TabItem('Use prompt as input'):
|
41 |
create_prompt_demo()
|
42 |
+
demo.queue(api_open=False, max_size=10).launch()
|
|
app_generated_image.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
|
|
5 |
import pathlib
|
6 |
import shlex
|
7 |
import subprocess
|
@@ -210,7 +211,7 @@ def create_prompt_demo() -> gr.Blocks:
|
|
210 |
result,
|
211 |
],
|
212 |
fn=process_example,
|
213 |
-
cache_examples=
|
214 |
)
|
215 |
|
216 |
extract_feature_button.click(
|
|
|
2 |
|
3 |
from __future__ import annotations
|
4 |
|
5 |
+
import os
|
6 |
import pathlib
|
7 |
import shlex
|
8 |
import subprocess
|
|
|
211 |
result,
|
212 |
],
|
213 |
fn=process_example,
|
214 |
+
cache_examples=os.getenv('CACHE_EXAMPLES'),
|
215 |
)
|
216 |
|
217 |
extract_feature_button.click(
|
app_real_image.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
from __future__ import annotations
|
4 |
|
5 |
import hashlib
|
|
|
6 |
import pathlib
|
7 |
import shlex
|
8 |
import subprocess
|
@@ -193,7 +194,7 @@ def create_real_image_demo():
|
|
193 |
result,
|
194 |
],
|
195 |
fn=process_example,
|
196 |
-
cache_examples=
|
197 |
)
|
198 |
|
199 |
extract_feature_button.click(
|
|
|
3 |
from __future__ import annotations
|
4 |
|
5 |
import hashlib
|
6 |
+
import os
|
7 |
import pathlib
|
8 |
import shlex
|
9 |
import subprocess
|
|
|
194 |
result,
|
195 |
],
|
196 |
fn=process_example,
|
197 |
+
cache_examples=os.getenv('CACHE_EXAMPLES'),
|
198 |
)
|
199 |
|
200 |
extract_feature_button.click(
|