Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,22 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from diffusers import StableDiffusionPipeline
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
)
|
| 10 |
-
pipe.to("cpu") # Ensure it's running on CPU
|
| 11 |
|
| 12 |
-
#
|
| 13 |
def generate_image(prompt):
|
| 14 |
-
# Generate image
|
| 15 |
image = pipe(prompt).images[0]
|
| 16 |
return image
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
outputs=gr.Image(),
|
| 23 |
-
title="Text-to-Image Generator (CPU Optimized)"
|
| 24 |
-
)
|
| 25 |
|
| 26 |
-
# Launch the
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load the model
|
| 6 |
+
model_id = "CompVis/stable-diffusion-v1-4-original" # Change this to any model you want
|
| 7 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
| 8 |
+
pipe = pipe.to("cpu") # Ensures the model runs on CPU if no GPU is available
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Function to generate an image from text
|
| 11 |
def generate_image(prompt):
|
| 12 |
+
# Generate image from prompt
|
| 13 |
image = pipe(prompt).images[0]
|
| 14 |
return image
|
| 15 |
|
| 16 |
+
# Gradio interface
|
| 17 |
+
iface = gr.Interface(fn=generate_image,
|
| 18 |
+
inputs=gr.Textbox(label="Enter a prompt"),
|
| 19 |
+
outputs=gr.Image(label="Generated Image"))
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Launch the interface
|
| 22 |
+
iface.launch()
|