Spaces:
Runtime error
Runtime error
Commit
·
5c80069
1
Parent(s):
092a751
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,39 @@
|
|
1 |
-
|
2 |
import torch
|
3 |
from torch import autocast
|
4 |
from diffusers import StableDiffusionPipeline
|
5 |
-
import gradio as gr
|
6 |
|
7 |
model_id = "CompVis/stable-diffusion-v1-4"
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
#device = torch.device('cpu' if not has_cuda else 'cuda')
|
12 |
pipe = pipe.to(device)
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
gr.
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
from torch import autocast
|
4 |
from diffusers import StableDiffusionPipeline
|
|
|
5 |
|
6 |
model_id = "CompVis/stable-diffusion-v1-4"
|
7 |
+
device = "cuda"
|
8 |
+
|
9 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token='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', torch_dtype=torch.float16, low_cpu_mem_usage=True)
|
|
|
10 |
pipe = pipe.to(device)
|
11 |
|
12 |
+
def inference(diffusion_prompt):
|
13 |
+
samples = 4
|
14 |
+
generator = torch.Generator(device=device)
|
15 |
+
torch.cuda.empty_cache()
|
16 |
+
with autocast("cuda"):
|
17 |
+
images_list = pipe(
|
18 |
+
[diffusion_prompt] * samples,
|
19 |
+
height=256, width=384,
|
20 |
+
num_inference_steps=50,
|
21 |
+
)
|
22 |
+
images = []
|
23 |
+
for i, image in enumerate(images_list["sample"]):
|
24 |
+
images.append(image)
|
25 |
+
return images
|
26 |
+
|
27 |
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("# Text to Image Generator")
|
30 |
+
with gr.Row():
|
31 |
+
prompt = gr.Textbox(
|
32 |
+
lines=1,
|
33 |
+
placeholder="Enter your prompt..",
|
34 |
+
interactive=True,
|
35 |
+
label="Prompt"
|
36 |
+
)
|
37 |
+
submit = gr.Button("Run")
|
38 |
+
submit.click(fn=inference, inputs=[prompt], outputs=[images])
|
39 |
+
demo.launch()
|