raahinaez commited on
Commit
9056236
·
verified ·
1 Parent(s): 4e187b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -1,17 +1,30 @@
1
  import torch
2
- from diffusers import FluxPipeline
 
3
 
4
- pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
5
- pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power
6
 
7
- prompt = "A cat holding a sign that says hello world"
8
- image = pipe(
9
- prompt,
10
- height=1024,
11
- width=1024,
12
- guidance_scale=3.5,
13
- num_inference_steps=50,
14
- max_sequence_length=512,
15
- generator=torch.Generator("cpu").manual_seed(0)
16
- ).images[0]
17
- image.save("flux-dev.png")
 
 
 
 
 
 
 
 
 
 
 
 
 
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()