Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,32 @@
|
|
| 1 |
import torch
|
| 2 |
-
import gradio as gr
|
| 3 |
from diffusers import StableDiffusion3Pipeline
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
image =
|
| 15 |
-
prompt
|
| 16 |
-
negative_prompt="
|
| 17 |
-
num_inference_steps=
|
| 18 |
-
|
| 19 |
-
width=1024,
|
| 20 |
-
guidance_scale=9.0
|
| 21 |
).images[0]
|
| 22 |
-
|
| 23 |
-
#image.show()
|
| 24 |
return image
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
print(interface)
|
|
|
|
| 1 |
import torch
|
|
|
|
| 2 |
from diffusers import StableDiffusion3Pipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load the Stable Diffusion pipeline
|
| 6 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(
|
| 7 |
+
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 8 |
+
torch_dtype=torch.float16
|
| 9 |
+
)
|
| 10 |
+
pipe = pipe.to("cuda")
|
| 11 |
+
|
| 12 |
+
# Function to generate images
|
| 13 |
+
def generate_image(prompt):
|
| 14 |
+
image = pipe(
|
| 15 |
+
prompt,
|
| 16 |
+
negative_prompt="",
|
| 17 |
+
num_inference_steps=28,
|
| 18 |
+
guidance_scale=7.0,
|
|
|
|
|
|
|
| 19 |
).images[0]
|
|
|
|
|
|
|
| 20 |
return image
|
| 21 |
|
| 22 |
+
# Create a Gradio interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=generate_image, # Function to call
|
| 25 |
+
inputs=gr.Textbox(label="Enter a prompt"), # Input component
|
| 26 |
+
outputs=gr.Image(label="Generated Image"), # Output component
|
| 27 |
+
title="Stable Diffusion 3 Image Generator",
|
| 28 |
+
description="Enter a prompt to generate an image using Stable Diffusion 3."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the Gradio app
|
| 32 |
+
iface.launch()
|
|
|
|
|
|