Zaiiida commited on
Commit
211963c
·
verified ·
1 Parent(s): a50031d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -185
app.py CHANGED
@@ -1,196 +1,48 @@
1
- import gradio as gr
2
- import numpy as np
3
- import random
4
- import spaces
5
- from diffusers import DiffusionPipeline
6
- import torch
7
-
8
- device = "cuda" if torch.cuda.is_available() else "cpu"
9
- model_repo_id = "stabilityai/stable-diffusion-3.5-large"
10
-
11
- if torch.cuda.is_available():
12
- torch_dtype = torch.bfloat16
13
- else:
14
- torch_dtype = torch.float32
15
-
16
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
17
- pipe = pipe.to(device)
18
-
19
- MAX_SEED = np.iinfo(np.int32).max
20
- MAX_IMAGE_SIZE = 1024
21
-
22
- @spaces.GPU(duration=65)
23
- def infer(
24
- prompt,
25
- negative_prompt="",
26
- seed=42,
27
- randomize_seed=False,
28
- width=1024,
29
- height=1024,
30
- guidance_scale=4.5,
31
- num_inference_steps=40,
32
- progress=gr.Progress(track_tqdm=True),
33
- ):
34
- if randomize_seed:
35
- seed = random.randint(0, MAX_SEED)
36
-
37
- generator = torch.Generator().manual_seed(seed)
38
-
39
- image = pipe(
40
- prompt=prompt,
41
- negative_prompt=negative_prompt,
42
- guidance_scale=guidance_scale,
43
- num_inference_steps=num_inference_steps,
44
- width=width,
45
- height=height,
46
- generator=generator,
47
- ).images[0]
48
-
49
- return image, seed
50
-
51
- examples = [
52
- "A border collie lying in some Fall leaves as the forest trees change colors",
53
- ]
54
-
55
- # Обновленный CSS
56
- custom_css = """
57
- body {
58
- background-color: #17181B;
59
- color: #AEB3B8;
60
- }
61
- button {
62
- background-color: #5271FF;
63
- color: #FFFFFF;
64
- border: none;
65
- }
66
- button:hover {
67
- background-color: #395BB5;
68
- }
69
- input[type="range"] {
70
- accent-color: #5271FF;
71
- }
72
- input[type="checkbox"]:checked {
73
- background-color: #5271FF;
74
- }
75
- .footer, footer {
76
- display: none !important;
77
- }
78
  #col-container {
79
  margin: 0 auto;
80
- max-width: 640px;
81
  }
82
- """
83
-
84
- with gr.Blocks() as demo:
85
- # Добавляем стили в начале с помощью gr.HTML()
86
- gr.HTML(f"<style>{custom_css}</style>")
87
-
88
- with gr.Column(elem_id="col-container"):
89
- gr.Markdown("Prompt")
90
-
91
- with gr.Row():
92
- prompt = gr.Text(
93
- label="Prompt",
94
- show_label=False,
95
- max_lines=1,
96
- placeholder="Enter your prompt",
97
- container=False,
98
- )
99
-
100
- run_button = gr.Button("Generate", scale=0, variant="primary")
101
 
102
- result = gr.Image(label="Result", show_label=False)
103
-
104
- with gr.Accordion("Advanced Settings", open=False):
105
- negative_prompt = gr.Text(
106
- label="Negative Prompt",
107
- max_lines=1,
108
- placeholder="Enter a negative prompt",
109
- visible=False,
110
- )
111
-
112
- seed = gr.Slider(
113
- label="Seed",
114
- minimum=0,
115
- maximum=MAX_SEED,
116
- step=1,
117
- value=0,
118
- )
119
-
120
- randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
121
 
122
- with gr.Row():
123
- width = gr.Slider(
124
- label="Width",
125
- minimum=512,
126
- maximum=MAX_IMAGE_SIZE,
127
- step=32,
128
- value=1024,
129
- )
130
 
131
- height = gr.Slider(
132
- label="Height",
133
- minimum=512,
134
- maximum=MAX_IMAGE_SIZE,
135
- step=32,
136
- value=1024,
137
- )
138
 
139
- with gr.Row():
140
- guidance_scale = gr.Slider(
141
- label="Guidance Scale",
142
- minimum=0.0,
143
- maximum=7.5,
144
- step=0.1,
145
- value=4.5,
146
- )
147
 
148
- num_inference_steps = gr.Slider(
149
- label="Number of Inference Steps",
150
- minimum=1,
151
- maximum=50,
152
- step=1,
153
- value=40,
154
- )
155
 
156
- gr.Examples(
157
- examples=examples,
158
- inputs=[prompt],
159
- outputs=[result, seed],
160
- fn=infer,
161
- cache_examples=True,
162
- cache_mode="lazy"
163
- )
164
 
165
- # Используем метод click для кнопки и submit для текстового поля
166
- run_button.click(
167
- fn=infer,
168
- inputs=[
169
- prompt,
170
- negative_prompt,
171
- seed,
172
- randomize_seed,
173
- width,
174
- height,
175
- guidance_scale,
176
- num_inference_steps,
177
- ],
178
- outputs=[result, seed],
179
- )
180
- prompt.submit(
181
- fn=infer,
182
- inputs=[
183
- prompt,
184
- negative_prompt,
185
- seed,
186
- randomize_seed,
187
- width,
188
- height,
189
- guidance_scale,
190
- num_inference_steps,
191
- ],
192
- outputs=[result, seed],
193
- )
194
 
195
- if __name__ == "__main__":
196
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True, show_api=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #col-container {
2
  margin: 0 auto;
3
+ max-width: 520px;
4
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ /* Кнопки */
7
+ .gr-button {
8
+ background-color: #5271FF !important; /* Основной цвет кнопки */
9
+ border-color: #5271FF !important; /* Граница кнопки */
10
+ color: white !important; /* Цвет текста кнопки */
11
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ .gr-button:hover,
14
+ .gr-button:focus,
15
+ .gr-button:active {
16
+ background-color: #3e5ac0 !important; /* Цвет кнопки при наведении или нажатии */
17
+ border-color: #3e5ac0 !important;
18
+ }
 
 
19
 
20
+ /* Ползунки */
21
+ .gr-slider .noUi-connect {
22
+ background: #5271FF !important; /* Цвет заполненной части ползунка */
23
+ }
 
 
 
24
 
25
+ .gr-slider .noUi-handle {
26
+ border-color: #5271FF !important; /* Цвет рукоятки ползунка */
27
+ }
 
 
 
 
 
28
 
29
+ .gr-slider .noUi-handle:focus,
30
+ .gr-slider .noUi-handle:active {
31
+ border-color: #3e5ac0 !important; /* Цвет рукоятки при фокусе или нажатии */
32
+ }
 
 
 
33
 
34
+ /* Чекбоксы */
35
+ .gr-checkbox label::before {
36
+ border-color: #5271FF !important; /* Цвет границы чекбокса */
37
+ }
 
 
 
 
38
 
39
+ .gr-checkbox input[type=checkbox]:checked + label::before {
40
+ background-color: #5271FF !important; /* Цвет фона чекбокса при выборе */
41
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
+ /* Текстовые поля и другие элементы */
44
+ input[type="text"]:focus,
45
+ textarea:focus {
46
+ border-color: #5271FF !important; /* Цвет границы текстовых полей при фокусе */
47
+ outline: none !important; /* Убирает стандартный outline */
48
+ }