Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Load the Stable Diffusion model
|
7 |
+
model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
|
8 |
+
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
+
|
10 |
+
def generate_image(prompt):
|
11 |
+
# Generate image from the model
|
12 |
+
with torch.no_grad():
|
13 |
+
image = model(prompt).images[0]
|
14 |
+
# Convert to PIL Image to display in Gradio
|
15 |
+
image = Image.fromarray(image.numpy())
|
16 |
+
return image
|
17 |
+
|
18 |
+
# Create a Gradio interface
|
19 |
+
interface = gr.Interface(fn=generate_image, inputs='text', outputs='image')
|
20 |
+
|
21 |
+
# Launch the interface
|
22 |
+
interface.launch()
|
23 |
|