Spaces:
Runtime error
Runtime error
update in the app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,50 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from diffusers import
|
4 |
|
5 |
-
#
|
6 |
-
model_id = "stabilityai/stable-diffusion-3.5-large"
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
pipe =
|
|
|
12 |
|
13 |
-
# Define
|
14 |
-
def generate_image(prompt):
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
return image
|
18 |
|
19 |
# Set up the Gradio interface
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from diffusers import StableDiffusion3Pipeline
|
4 |
|
5 |
+
# Check if CUDA is available and set the device accordingly
|
|
|
6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
7 |
|
8 |
+
# Load the Stable Diffusion 3.5 Large model
|
9 |
+
model_id = "stabilityai/stable-diffusion-3.5-large"
|
10 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
11 |
+
pipe.to(device)
|
12 |
|
13 |
+
# Define the image generation function
|
14 |
+
def generate_image(prompt, negative_prompt, width, height, guidance_scale, num_inference_steps, seed):
|
15 |
+
generator = torch.manual_seed(seed) if seed else None
|
16 |
+
image = pipe(
|
17 |
+
prompt=prompt,
|
18 |
+
negative_prompt=negative_prompt,
|
19 |
+
width=width,
|
20 |
+
height=height,
|
21 |
+
guidance_scale=guidance_scale,
|
22 |
+
num_inference_steps=num_inference_steps,
|
23 |
+
generator=generator
|
24 |
+
).images[0]
|
25 |
return image
|
26 |
|
27 |
# Set up the Gradio interface
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("# Stable Diffusion 3.5 Large Image Generator")
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
|
33 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here")
|
34 |
+
width = gr.Slider(label="Width", minimum=512, maximum=1024, step=64, value=512)
|
35 |
+
height = gr.Slider(label="Height", minimum=512, maximum=1024, step=64, value=512)
|
36 |
+
guidance_scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=20.0, step=0.5, value=7.5)
|
37 |
+
num_inference_steps = gr.Slider(label="Inference Steps", minimum=1, maximum=100, step=1, value=50)
|
38 |
+
seed = gr.Number(label="Seed", value=42, precision=0)
|
39 |
+
generate_button = gr.Button("Generate Image")
|
40 |
+
with gr.Column():
|
41 |
+
output_image = gr.Image(label="Generated Image")
|
42 |
+
|
43 |
+
generate_button.click(
|
44 |
+
fn=generate_image,
|
45 |
+
inputs=[prompt, negative_prompt, width, height, guidance_scale, num_inference_steps, seed],
|
46 |
+
outputs=output_image
|
47 |
+
)
|
48 |
|
49 |
+
if __name__ == "__main__":
|
50 |
+
demo.launch()
|