borsojj commited on
Commit
1280c43
·
verified ·
1 Parent(s): 0fad32a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -58,7 +58,6 @@ try:
58
  tuned_unet_repo_id,
59
  torch_dtype=torch_dtype, # Carrega com mesmo dtype
60
  token=hf_token # Usa o token para acessar repo privado
61
- # low_cpu_mem_usage=False # Pode precisar desativar se der erro OOM aqui
62
  )
63
  print("UNet treinado carregado. Substituindo UNet no pipeline...")
64
  pipe.unet = tuned_unet # A SUBSTITUIÇÃO
@@ -74,7 +73,6 @@ try:
74
  print(loading_error_message)
75
  DESCRIPTION += "\n" + loading_error_message
76
 
77
-
78
  # Configura o scheduler (como antes)
79
  pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
80
  print(f"Scheduler configurado para: {pipe.scheduler.__class__.__name__}")
@@ -90,7 +88,6 @@ except Exception as e:
90
  DESCRIPTION += "\n" + loading_error_message
91
  pipe = None
92
 
93
-
94
  # Função generate (sem alterações significativas)
95
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
96
  if randomize_seed: seed = random.randint(0, MAX_SEED)
@@ -100,7 +97,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
100
  def generate(
101
  prompt: str,
102
  negative_prompt: str = "",
103
- use_negative_prompt: bool = True,
104
  seed: int = 0,
105
  width: int = 1024,
106
  height: int = 1024,
@@ -125,14 +122,19 @@ def generate(
125
  print(f"Erro durante a geração: {e}")
126
  raise gr.Error(f"Erro durante a geração: {e}")
127
 
128
-
129
- # Interface Gradio (sem alterações significativas)
130
- examples = [ "photo of a futuristic city skyline at sunset, high detail", "an oil painting of a cute cat wearing a wizard hat", "Astronaut in a jungle, cold color palette, oil pastel, detailed, 8k", "An alien grasping a sign board contain word 'Flash', futuristic, neonpunk, detailed" ]
 
 
 
 
131
  css = ".gradio-container { max-width: 800px !important; margin: 0 auto !important; } h1{ text-align:center }"
132
  with gr.Blocks(css=css) as demo:
133
  gr.Markdown(f"""# SDXL Base com UNet Fine-tuned (`{tuned_unet_repo_id}`)
134
  Base: `{base_model_id}`
135
- {DESCRIPTION}""")
 
136
  with gr.Group():
137
  with gr.Row():
138
  prompt = gr.Text(label="Prompt", show_label=False, max_lines=3, placeholder="Descreva a imagem...", container=False)
@@ -140,8 +142,15 @@ with gr.Blocks(css=css) as demo:
140
  result = gr.Gallery(label="Resultado", show_label=False, elem_id="gallery", columns=1, height=768)
141
  with gr.Accordion("Opções Avançadas", open=False):
142
  with gr.Row():
143
- use_negative_prompt = gr.Checkbox(label="Usar prompt negativo", value=True)
144
- negative_prompt = gr.Text(label="Prompt Negativo", max_lines=3, lines=2, placeholder="O que NÃO ver...", value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW", visible=True)
 
 
 
 
 
 
 
145
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
146
  randomize_seed = gr.Checkbox(label="Seed Aleatória", value=True)
147
  with gr.Row():
 
58
  tuned_unet_repo_id,
59
  torch_dtype=torch_dtype, # Carrega com mesmo dtype
60
  token=hf_token # Usa o token para acessar repo privado
 
61
  )
62
  print("UNet treinado carregado. Substituindo UNet no pipeline...")
63
  pipe.unet = tuned_unet # A SUBSTITUIÇÃO
 
73
  print(loading_error_message)
74
  DESCRIPTION += "\n" + loading_error_message
75
 
 
76
  # Configura o scheduler (como antes)
77
  pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
78
  print(f"Scheduler configurado para: {pipe.scheduler.__class__.__name__}")
 
88
  DESCRIPTION += "\n" + loading_error_message
89
  pipe = None
90
 
 
91
  # Função generate (sem alterações significativas)
92
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
93
  if randomize_seed: seed = random.randint(0, MAX_SEED)
 
97
  def generate(
98
  prompt: str,
99
  negative_prompt: str = "",
100
+ use_negative_prompt: bool = False,
101
  seed: int = 0,
102
  width: int = 1024,
103
  height: int = 1024,
 
122
  print(f"Erro durante a geração: {e}")
123
  raise gr.Error(f"Erro durante a geração: {e}")
124
 
125
+ # Interface Gradio
126
+ examples = [
127
+ "photo of a futuristic city skyline at sunset, high detail",
128
+ "an oil painting of a cute cat wearing a wizard hat",
129
+ "Astronaut in a jungle, cold color palette, oil pastel, detailed, 8k",
130
+ "An alien grasping a sign board contain word 'Flash', futuristic, neonpunk, detailed"
131
+ ]
132
  css = ".gradio-container { max-width: 800px !important; margin: 0 auto !important; } h1{ text-align:center }"
133
  with gr.Blocks(css=css) as demo:
134
  gr.Markdown(f"""# SDXL Base com UNet Fine-tuned (`{tuned_unet_repo_id}`)
135
  Base: `{base_model_id}`
136
+ {DESCRIPTION}
137
+ **Aviso:** O filtro de conteúdo explícito foi desativado. Use prompts com cuidado.""")
138
  with gr.Group():
139
  with gr.Row():
140
  prompt = gr.Text(label="Prompt", show_label=False, max_lines=3, placeholder="Descreva a imagem...", container=False)
 
142
  result = gr.Gallery(label="Resultado", show_label=False, elem_id="gallery", columns=1, height=768)
143
  with gr.Accordion("Opções Avançadas", open=False):
144
  with gr.Row():
145
+ use_negative_prompt = gr.Checkbox(label="Usar prompt negativo", value=False)
146
+ negative_prompt = gr.Text(
147
+ label="Prompt Negativo",
148
+ max_lines=3,
149
+ lines=2,
150
+ placeholder="O que evitar na imagem (ex.: blurry, deformed)...",
151
+ value="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, blurry, amputation",
152
+ visible=False
153
+ )
154
  seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
155
  randomize_seed = gr.Checkbox(label="Seed Aleatória", value=True)
156
  with gr.Row():