Spaces:
Runtime error
Runtime error
Commit
·
b321c35
1
Parent(s):
49c5b35
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,33 @@
|
|
|
|
1 |
import torch
|
2 |
from diffusers import StableDiffusionPipeline
|
|
|
|
|
3 |
|
|
|
4 |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
|
5 |
-
|
6 |
pipe = pipe.to("cuda")
|
7 |
|
8 |
-
prompt
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
+
from PIL import Image
|
5 |
+
import io
|
6 |
|
7 |
+
# Load the model
|
8 |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
|
|
|
9 |
pipe = pipe.to("cuda")
|
10 |
|
11 |
+
def generate_image(prompt):
|
12 |
+
image = pipe(prompt).images[0]
|
13 |
+
# Save the image to a bytes buffer
|
14 |
+
img_buffer = io.BytesIO()
|
15 |
+
image.save(img_buffer, format="PNG")
|
16 |
+
img_buffer.seek(0)
|
17 |
+
return img_buffer
|
18 |
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=generate_image,
|
21 |
+
inputs="text",
|
22 |
+
outputs="image",
|
23 |
+
layout="vertical",
|
24 |
+
inputs_label="Enter Prompt",
|
25 |
+
outputs_label="Generated Image",
|
26 |
+
examples=[
|
27 |
+
["a photograph of an astronaut riding a horse"],
|
28 |
+
["a beautiful sunset over the mountains"]
|
29 |
+
]
|
30 |
+
)
|
31 |
|
32 |
+
if __name__ == "__main__":
|
33 |
+
iface.launch()
|