Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,9 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
pipe =
|
| 7 |
-
|
| 8 |
-
# Ensure that the model runs on CPU
|
| 9 |
-
pipe = pipe.to("cpu") # Use CPU instead of CUDA (GPU)
|
| 10 |
-
|
| 11 |
-
def generate_image(prompt):
|
| 12 |
-
# Generate image based on the user's prompt
|
| 13 |
-
image = pipe(prompt).images[0]
|
| 14 |
-
|
| 15 |
-
return image
|
| 16 |
-
|
| 17 |
-
# Create a Gradio interface
|
| 18 |
-
iface = gr.Interface(
|
| 19 |
-
fn=generate_image
|
| 20 |
-
, # Function to call when the user submits a prompt
|
| 21 |
-
inputs="text", # Input is a text field for the user to type their prompt
|
| 22 |
-
outputs="image", # Output is an image, generated by the model
|
| 23 |
-
live=True # Make the interface responsive in real-time
|
| 24 |
-
)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
|
| 4 |
+
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
|
| 5 |
+
pipe = pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
prompt = "a photo of an astronaut riding a horse on mars"
|
| 8 |
+
image = pipe(prompt).images[0]
|
| 9 |
+
image
|