Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,23 +3,28 @@ import gradio as gr
|
|
| 3 |
from diffusers import StableDiffusionPipeline
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
image = pipe(prompt, num_inference_steps=20, guidance_scale=7.5).images[0]
|
| 14 |
return image
|
| 15 |
|
| 16 |
-
#
|
| 17 |
demo = gr.Interface(
|
| 18 |
fn=generate_image,
|
| 19 |
inputs=gr.Textbox(label="Enter your prompt"),
|
| 20 |
-
outputs=gr.Image(
|
| 21 |
-
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
demo.launch(
|
|
|
|
|
|
| 3 |
from diffusers import StableDiffusionPipeline
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
# Load Stable Diffusion pipeline (open source)
|
| 7 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 8 |
+
"runwayml/stable-diffusion-v1-5",
|
| 9 |
+
torch_dtype=torch.float32
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# Force CPU (free Spaces usually don’t allow GPU)
|
| 13 |
+
pipe.to("cpu")
|
| 14 |
|
| 15 |
+
def generate_image(prompt):
|
| 16 |
+
image = pipe(prompt, guidance_scale=7.5).images[0]
|
|
|
|
| 17 |
return image
|
| 18 |
|
| 19 |
+
# Gradio UI for testing
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=generate_image,
|
| 22 |
inputs=gr.Textbox(label="Enter your prompt"),
|
| 23 |
+
outputs=gr.Image(label="Generated Image"),
|
| 24 |
+
title="Stable Diffusion Text-to-Image",
|
| 25 |
+
description="Enter a prompt and generate an image using Stable Diffusion."
|
| 26 |
)
|
| 27 |
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|
| 30 |
+
|