ytrsoymr commited on
Commit
ed9f62a
·
verified ·
1 Parent(s): f6437ac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from diffusers import StableDiffusion3Pipeline
4
+ import random
5
+
6
+ # Load model
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ pipe = StableDiffusion3Pipeline.from_pretrained(
9
+ "stabilityai/stable-diffusion-3-medium-diffusers",
10
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
11
+ ).to(device)
12
+
13
+ st.title("🎨 Stable Diffusion 3 Medium - Streamlit")
14
+
15
+ prompt = st.text_input("Prompt", "Astronaut in a jungle, cold color palette, 8k")
16
+ negative_prompt = st.text_input("Negative Prompt", "blurry, low quality, text")
17
+ guidance_scale = st.slider("Guidance Scale", 0.0, 10.0, 5.0)
18
+ num_inference_steps = st.slider("Inference Steps", 1, 50, 28)
19
+ width = st.slider("Image Width", 256, 1344, 1024, step=64)
20
+ height = st.slider("Image Height", 256, 1344, 1024, step=64)
21
+ random_seed = st.checkbox("Randomize Seed", value=True)
22
+ seed = random.randint(0, 2**32 - 1) if random_seed else st.number_input("Seed", value=0, step=1)
23
+
24
+ if st.button("Generate Image"):
25
+ with st.spinner("Generating..."):
26
+ generator = torch.Generator().manual_seed(seed)
27
+ image = pipe(
28
+ prompt=prompt,
29
+ negative_prompt=negative_prompt,
30
+ guidance_scale=guidance_scale,
31
+ num_inference_steps=num_inference_steps,
32
+ width=width,
33
+ height=height,
34
+ generator=generator
35
+ ).images[0]
36
+ st.image(image, caption="Generated Image")
37
+ st.write(f"Seed used: {seed}")