Jagrut Thakare commited on
Commit
261ecad
Β·
1 Parent(s): 8013c8a
Files changed (3) hide show
  1. README.md +9 -7
  2. app.py +153 -0
  3. requirements.txt +6 -0
README.md CHANGED
@@ -1,12 +1,14 @@
1
  ---
2
- title: SD3.5 Large
3
- emoji: πŸŒ–
4
- colorFrom: green
5
- colorTo: pink
6
  sdk: gradio
7
- sdk_version: 5.22.0
8
  app_file: app.py
9
- pinned: false
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Stable Diffusion 3.5 Large Turbo
3
+ emoji: πŸƒ
4
+ colorFrom: purple
5
+ colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 5.3.0
8
  app_file: app.py
9
+ pinned: true
10
+ license: other
11
+ short_description: Generate images with SD3.5
12
  ---
13
 
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ import os
5
+ import spaces
6
+ from diffusers import DiffusionPipeline
7
+ import torch
8
+ from huggingface_hub import login
9
+ login(os.getenv("HF_TOKEN"))
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+ model_repo_id = "stabilityai/stable-diffusion-3.5-large"
12
+
13
+ if torch.cuda.is_available():
14
+ torch_dtype = torch.bfloat16
15
+ else:
16
+ torch_dtype = torch.float32
17
+
18
+ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype, use_safetensors=True)
19
+ if torch.cuda.is_available():
20
+ pipe = pipe.to(device, dtype=torch.bfloat16)
21
+ torch_dtype = torch.bfloat16
22
+ else :
23
+ pipe = pipe.to(device, dtype=torch.float32)
24
+ torch_dtype = torch.float32
25
+
26
+ MAX_SEED = np.iinfo(np.int32).max
27
+ MAX_IMAGE_SIZE = 1024
28
+
29
+ @spaces.GPU
30
+ def infer(
31
+ prompt,
32
+ negative_prompt="",
33
+ seed=42,
34
+ randomize_seed=False,
35
+ width=1024,
36
+ height=1024,
37
+ guidance_scale=0.0,
38
+ num_inference_steps=4,
39
+ progress=gr.Progress(track_tqdm=True),
40
+ ):
41
+ if randomize_seed:
42
+ seed = random.randint(0, MAX_SEED)
43
+
44
+ generator = torch.Generator().manual_seed(seed)
45
+
46
+ image = pipe(
47
+ prompt=prompt,
48
+ negative_prompt=negative_prompt,
49
+ guidance_scale=guidance_scale,
50
+ num_inference_steps=num_inference_steps,
51
+ width=width,
52
+ height=height,
53
+ generator=generator,
54
+ ).images[0]
55
+
56
+ return image, seed
57
+
58
+
59
+ examples = [
60
+ "A capybara wearing a suit holding a sign that reads Hello World",
61
+ ]
62
+
63
+ css = """
64
+ #col-container {
65
+ margin: 0 auto;
66
+ max-width: 640px;
67
+ }
68
+ """
69
+
70
+ with gr.Blocks(css=css) as demo:
71
+ with gr.Column(elem_id="col-container"):
72
+ gr.Markdown(" # Stable Diffusion 3.5 Large Turbo (8B)")
73
+
74
+ with gr.Row():
75
+ prompt = gr.Text(
76
+ label="Prompt",
77
+ max_lines=5,
78
+ placeholder="Enter your prompt",
79
+ )
80
+ negative_prompt = gr.Text(
81
+ label="Negative prompt",
82
+ max_lines=5,
83
+ placeholder="Enter a negative prompt",
84
+ )
85
+ run_button = gr.Button("Run", scale=0, variant="primary")
86
+
87
+ result = gr.Image(label="Result", show_label=False)
88
+
89
+ with gr.Accordion("Advanced Settings", open=False):
90
+
91
+ seed = gr.Slider(
92
+ label="Seed",
93
+ minimum=0,
94
+ maximum=MAX_SEED,
95
+ step=1,
96
+ value=0,
97
+ )
98
+
99
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
100
+
101
+ with gr.Row():
102
+ width = gr.Slider(
103
+ label="Width",
104
+ minimum=512,
105
+ maximum=MAX_IMAGE_SIZE,
106
+ step=32,
107
+ value=1024,
108
+ )
109
+
110
+ height = gr.Slider(
111
+ label="Height",
112
+ minimum=512,
113
+ maximum=MAX_IMAGE_SIZE,
114
+ step=32,
115
+ value=1024,
116
+ )
117
+
118
+ with gr.Row():
119
+ guidance_scale = gr.Slider(
120
+ label="Guidance scale",
121
+ minimum=0.0,
122
+ maximum=7.5,
123
+ step=0.1,
124
+ value=0.0,
125
+ )
126
+
127
+ num_inference_steps = gr.Slider(
128
+ label="Number of inference steps",
129
+ minimum=1,
130
+ maximum=50,
131
+ step=1,
132
+ value=4,
133
+ )
134
+
135
+ gr.Examples(examples=examples, inputs=[prompt], outputs=[result, seed], fn=infer, cache_examples=True, cache_mode="lazy")
136
+ gr.on(
137
+ triggers=[run_button.click, prompt.submit],
138
+ fn=infer,
139
+ inputs=[
140
+ prompt,
141
+ negative_prompt,
142
+ seed,
143
+ randomize_seed,
144
+ width,
145
+ height,
146
+ guidance_scale,
147
+ num_inference_steps,
148
+ ],
149
+ outputs=[result, seed],
150
+ )
151
+
152
+ if __name__ == "__main__":
153
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ accelerate
2
+ diffusers
3
+ torch
4
+ transformers
5
+ git+https://github.com/huggingface/diffusers.git
6
+ sentencepiece