Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
import torch
|
| 2 |
-
from diffusers import
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import StableDiffusion3Pipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load model (auto CPU/GPU)
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
|
| 8 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(
|
| 9 |
+
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 10 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 11 |
+
)
|
| 12 |
+
pipe.to(device)
|
| 13 |
+
|
| 14 |
+
def generate(prompt):
|
| 15 |
+
image = pipe(
|
| 16 |
+
prompt,
|
| 17 |
+
negative_prompt="",
|
| 18 |
+
num_inference_steps=28,
|
| 19 |
+
guidance_scale=7.0,
|
| 20 |
+
).images[0]
|
| 21 |
+
return image
|
| 22 |
+
|
| 23 |
+
ui = gr.Interface(
|
| 24 |
+
fn=generate,
|
| 25 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
| 26 |
+
outputs=gr.Image(label="Generated Image"),
|
| 27 |
+
title="Stable Diffusion 3 Medium - HF Space",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
ui.launch()
|