LEIDIA commited on
Commit
6b72774
·
verified ·
1 Parent(s): 5dc3a63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -120
app.py CHANGED
@@ -1,39 +1,27 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
- import os
5
-
6
- # import spaces #[uncomment to use ZeroGPU]
7
- from diffusers import DiffusionPipeline
8
- from diffusers import StableDiffusionPipeline
9
- from diffusers import OnnxRuntimeModel
10
  import torch
 
 
11
 
12
- from huggingface_hub import login
13
-
14
-
15
  device = "cuda" if torch.cuda.is_available() else "cpu"
16
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
17
-
18
 
19
-
20
- if torch.cuda.is_available():
21
- torch_dtype = torch.float16
22
- else:
23
- torch_dtype = torch.float32
24
 
25
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
26
  pipe = pipe.to(device)
27
 
 
28
  MAX_SEED = np.iinfo(np.int32).max
29
  MAX_IMAGE_SIZE = 752
30
 
 
 
31
 
32
- from datasets import load_dataset, Dataset
33
-
34
- dataset = load_dataset("LEIDIA/Data_Womleimg") # Exemplo do seu dataset no Hugging Face
35
-
36
- # Adicionar descrições ao dataset
37
  descriptions = [
38
  "A woman wearing a full blue leather catsuit",
39
  "A woman in a black leather pants",
@@ -41,23 +29,11 @@ descriptions = [
41
  "A woman in long red leather jacket, red leather shorts and a tigh high red leather boots",
42
  "A legs woman in cream color leather pants",
43
  "A woman in purple leather leggings with tigh high black leather boots",
44
- "A woman in black leather top and a long black leather skirt ",
45
- "A blonde long hair curly woman using a yellow mini tight leather skirt",
46
- "A thin asian woman using a thigh long black leather dress",
47
- "A simple high brown leather boots",
48
- "A beautiful face brunette woman using a leather clothes",
49
- "A beautiful brunette woman wearing a sleeveless black dress, seated at a bar, She is holding a glass champagne, The background is softly lit, with warm lighting and blurred bottles on shelves, creating a cozy and elegant atmosphere.",
50
- "A curly blonde woman is wearing a bold and stylish outfit red leather jacket paired with black leather tight pants and red high-heeled leather boots, The outfit has a modern and edgy vibe, with a focus on vibrant colors and sleek materials.",
51
- "Ebony woman standing outdoors against a backdrop of rolling hills and a cloudy sky, wearing a striking outfit consisting of a red leather shirt, a black leather mini corset, and a red plaid skirt with a long panel on one side,also wearing knee-high red lace-up leather boots, Their hair is voluminous and styled in natural curls, The setting appears to be a grassy landscape.",
52
- "Blonde curly woman is wearing a fitted, shiny blue outfit made of what appears to be leather or vinyl clothes, The ensemble includes a jacket and pants with metallic buttons and a belt at the waist, They are also wearing knee-high boots with lacing details, Their hair is styled in voluminous, curly blonde locks. The setting is a simple, neutral-colored room with a concrete or stone-like wall and floor.",
53
- "The girl is wearing a black leather outfit include top,legging and sleeves,consisting of a fitted top with a heart-shaped cutout and high-waisted pants, The ensemble includes a purple cape and the individual has long purple hair,The style is reminiscent of superhero or fantasy attire, emphasizing a bold and sleek look.",
54
- "The girl dressed in a sleek, black leather outfit. The attire includes a cropped top with a zip closure and a high-waisted bottom, both designed to accentuate the figure's silhouette, The individual has long, pink hair styled in a ponytail, and is wearing long black gloves that reach the upper arms. The background appears to be softly lit, enhancing the glossy texture of the leather,The overall look is bold and fashion-forward, with a striking color contrast between the black and pink elements.",
55
- "a girl wearing a form-fitting black leather top that highlights their physique, The top has a high neckline and is sleeveless, emphasizing the shoulders and arms, The individual has long, pink hair cascading down, adding a striking contrast to the outfit. The background is a light, neutral color, which helps to accentuate the subject, The overall aesthetic is bold and fashion-forward."
56
- # Adicione uma descrição para cada imagem no dataset
57
  ]
58
 
59
-
60
  def infer(prompt, num_inference_steps):
 
61
  image = pipe(
62
  prompt=prompt,
63
  num_inference_steps=num_inference_steps,
@@ -66,9 +42,9 @@ def infer(prompt, num_inference_steps):
66
  ).images[0]
67
  return image
68
 
 
69
 
70
- # @spaces.GPU #[uncomment to use ZeroGPU]
71
- def infer(
72
  prompt,
73
  negative_prompt,
74
  seed,
@@ -77,7 +53,6 @@ def infer(
77
  height,
78
  guidance_scale,
79
  num_inference_steps,
80
- progress=gr.Progress(track_tqdm=True),
81
  ):
82
  if randomize_seed:
83
  seed = random.randint(0, MAX_SEED)
@@ -96,18 +71,6 @@ def infer(
96
 
97
  return image, seed
98
 
99
-
100
- examples = [
101
- " A Woman using Leather Pants "
102
- ]
103
-
104
- css = """
105
- #col-container {
106
- margin: 0 auto;
107
- max-width: 640px;
108
- }
109
- """
110
-
111
  # Interface Gradio
112
  with gr.Blocks() as demo:
113
  with gr.Column(elem_id="col-container"):
@@ -122,90 +85,76 @@ with gr.Blocks() as demo:
122
  container=False,
123
  )
124
 
125
- run_button = gr.Button("Run", scale=0, variant="primary")
126
-
127
- result = gr.Image(label="Result", show_label=False)
128
-
129
-
130
- with gr.Row():
131
- generate_button = gr.Button("Generate")
132
- result = gr.Image(label="Generated Image")
133
- generate_button.click(infer, inputs=[prompt, num_inference_steps], outputs=result)
134
-
135
- demo.launch()
136
 
137
- run_button = gr.Button("Run", scale=0, variant="primary")
 
 
138
 
139
- result = gr.Image(label="Result", show_label=False)
 
 
 
 
 
140
 
 
141
  with gr.Accordion("Advanced Settings", open=False):
142
- negative_prompt = gr.Text(
143
- label="Negative prompt",
144
- max_lines=1,
145
- placeholder="Enter a negative prompt",
146
- visible=False,
147
- )
148
 
149
- seed = gr.Slider(
150
- label="Seed",
151
- minimum=0,
152
- maximum=MAX_SEED,
153
- step=1,
154
- value=0,
155
- )
156
 
157
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
158
 
159
- with gr.Row():
160
- width = gr.Slider(
161
  label="Width",
162
- minimum=0,
163
  maximum=MAX_IMAGE_SIZE,
164
  step=8,
165
- alue=600, # Replace with defaults that work for your model
166
- )
167
 
168
- height = gr.Slider(
169
- label="Height",
170
- minimum=0,
171
- maximum=MAX_IMAGE_SIZE,
172
- step=8,
173
- value=752, # Replace with defaults that work for your model
174
- )
175
 
176
- with gr.Row():
177
- guidance_scale = gr.Slider(
178
- label="Guidance scale",
179
- minimum=0.0,
180
- maximum=1.0,
181
- step=0.1,
182
- value=0.0, # Replace with defaults that work for your model
183
- )
184
 
185
- num_inference_steps = gr.Slider(
186
- label="Number of inference steps",
187
- minimum=1,
188
- maximum=50, # Alterado para um máximo mais realista
189
- step=1,
190
- value=15, # Valor padrão ajustado
191
- )
192
-
193
-
194
- gr.Examples(examples=examples, inputs=[prompt])
195
- gr.on(
196
- triggers=[run_button.click, prompt.submit],
197
- fn=infer,
198
- inputs=[
199
- prompt,
200
- negative_prompt,
201
- seed,
202
- randomize_seed,
203
- width,
204
- height,
205
- guidance_scale,
206
- num_inference_steps,
207
  ],
208
- outputs=[result, seed],
209
  )
210
 
211
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
 
 
 
 
 
 
4
  import torch
5
+ from diffusers import DiffusionPipeline
6
+ from datasets import load_dataset
7
 
8
+ # Configurações do dispositivo e modelo
 
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ model_repo_id = "stabilityai/sdxl-turbo" # Substitua pelo modelo desejado
 
11
 
12
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
 
 
 
 
13
 
14
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
15
  pipe = pipe.to(device)
16
 
17
+ # Definições de parâmetros gerais
18
  MAX_SEED = np.iinfo(np.int32).max
19
  MAX_IMAGE_SIZE = 752
20
 
21
+ # Carregando o dataset do Hugging Face
22
+ dataset = load_dataset("LEIDIA/Data_Womleimg")
23
 
24
+ # Adicionando descrições ao dataset
 
 
 
 
25
  descriptions = [
26
  "A woman wearing a full blue leather catsuit",
27
  "A woman in a black leather pants",
 
29
  "A woman in long red leather jacket, red leather shorts and a tigh high red leather boots",
30
  "A legs woman in cream color leather pants",
31
  "A woman in purple leather leggings with tigh high black leather boots",
32
+ # Adicione mais descrições conforme necessário
 
 
 
 
 
 
 
 
 
 
 
 
33
  ]
34
 
 
35
  def infer(prompt, num_inference_steps):
36
+ """Função para gerar a imagem baseada no prompt."""
37
  image = pipe(
38
  prompt=prompt,
39
  num_inference_steps=num_inference_steps,
 
42
  ).images[0]
43
  return image
44
 
45
+ # Função completa para inferência com mais parâmetros
46
 
47
+ def advanced_infer(
 
48
  prompt,
49
  negative_prompt,
50
  seed,
 
53
  height,
54
  guidance_scale,
55
  num_inference_steps,
 
56
  ):
57
  if randomize_seed:
58
  seed = random.randint(0, MAX_SEED)
 
71
 
72
  return image, seed
73
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  # Interface Gradio
75
  with gr.Blocks() as demo:
76
  with gr.Column(elem_id="col-container"):
 
85
  container=False,
86
  )
87
 
88
+ # Slider para definir o número de passos de inferência
89
+ num_inference_steps = gr.Slider(
90
+ label="Number of inference steps",
91
+ minimum=1,
92
+ maximum=50,
93
+ step=1,
94
+ value=15,
95
+ )
 
 
 
96
 
97
+ # Botão para gerar a imagem
98
+ generate_button = gr.Button("Generate")
99
+ result = gr.Image(label="Generated Image")
100
 
101
+ # Clique no botão para gerar a imagem
102
+ generate_button.click(
103
+ infer,
104
+ inputs=[prompt, num_inference_steps],
105
+ outputs=result,
106
+ )
107
 
108
+ # Configurações avançadas
109
  with gr.Accordion("Advanced Settings", open=False):
110
+ negative_prompt = gr.Textbox(
111
+ label="Negative prompt",
112
+ max_lines=1,
113
+ placeholder="Enter a negative prompt",
114
+ )
 
115
 
116
+ seed = gr.Slider(
117
+ label="Seed",
118
+ minimum=0,
119
+ maximum=MAX_SEED,
120
+ step=1,
121
+ value=0,
122
+ )
123
 
124
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
125
 
126
+ with gr.Row():
127
+ width = gr.Slider(
128
  label="Width",
129
+ minimum=64,
130
  maximum=MAX_IMAGE_SIZE,
131
  step=8,
132
+ value=512,
133
+ )
134
 
135
+ height = gr.Slider(
136
+ label="Height",
137
+ minimum=64,
138
+ maximum=MAX_IMAGE_SIZE,
139
+ step=8,
140
+ value=512,
141
+ )
142
 
143
+ guidance_scale = gr.Slider(
144
+ label="Guidance scale",
145
+ minimum=0.0,
146
+ maximum=20.0,
147
+ step=0.5,
148
+ value=7.5,
149
+ )
 
150
 
151
+ # Exemplos de prompts
152
+ gr.Examples(
153
+ examples=[
154
+ "A woman wearing leather pants",
155
+ "A woman in a red leather jacket",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  ],
157
+ inputs=[prompt],
158
  )
159
 
160
  if __name__ == "__main__":