Spaces:
Runtime error
Runtime error
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,24 @@ import gradio as gr
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
model_id = "
|
| 7 |
-
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def generate_image(prompt):
|
| 11 |
image = pipeline(prompt).images[0]
|
| 12 |
return image
|
| 13 |
|
| 14 |
-
# Define the Gradio interface
|
| 15 |
interface = gr.Interface(
|
| 16 |
fn=generate_image,
|
| 17 |
inputs=gr.Textbox(label="Enter your text prompt"),
|
| 18 |
outputs=gr.Image(type="pil"),
|
| 19 |
title="Text-to-Image Generator",
|
| 20 |
-
description="Enter a prompt, and the AI will generate an image based on it."
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# Launch the app
|
| 24 |
if __name__ == "__main__":
|
| 25 |
interface.launch()
|
|
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Load a smaller model if running on CPU
|
| 6 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
| 7 |
+
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 8 |
+
|
| 9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
+
pipeline.to(device)
|
| 11 |
|
| 12 |
def generate_image(prompt):
|
| 13 |
image = pipeline(prompt).images[0]
|
| 14 |
return image
|
| 15 |
|
|
|
|
| 16 |
interface = gr.Interface(
|
| 17 |
fn=generate_image,
|
| 18 |
inputs=gr.Textbox(label="Enter your text prompt"),
|
| 19 |
outputs=gr.Image(type="pil"),
|
| 20 |
title="Text-to-Image Generator",
|
| 21 |
+
description="Enter a prompt, and the AI will generate an image based on it."
|
| 22 |
)
|
| 23 |
|
|
|
|
| 24 |
if __name__ == "__main__":
|
| 25 |
interface.launch()
|