wpbcpaz commited on
Commit
b2c7d5b
·
verified ·
1 Parent(s): 3300ad1

Update app.py

Browse files

Alterações de incremento de funcionalidades slider e temperatura

Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -57,7 +57,7 @@ ESTILOS_DISPONIVEIS = [
57
  # FUNÇÕES DE GERAÇÃO (adaptadas da Aula 8)
58
  # ============================================
59
 
60
- def gerar_texto(tema, nicho, estilo):
61
  """
62
  Gera texto usando API do Hugging Face
63
  """
@@ -90,7 +90,7 @@ Escreva apenas a legenda, sem introduções ou explicações."""
90
  }
91
  ],
92
  "max_tokens": 350,
93
- "temperature": 0.7,
94
  "stream": False
95
  }
96
 
@@ -181,7 +181,7 @@ def gerar_imagem(descricao):
181
  # FUNÇÃO PRINCIPAL PARA O GRADIO
182
  # ============================================
183
 
184
- def gerar_post_interface(tema, nicho, estilo, descricao_imagem, gerar_img):
185
  """
186
  Função principal que o Gradio chama quando usuário clica no botão.
187
 
@@ -202,7 +202,7 @@ def gerar_post_interface(tema, nicho, estilo, descricao_imagem, gerar_img):
202
 
203
 
204
  # Etapa 1: Gerar texto
205
- texto = gerar_texto(tema, nicho, estilo)
206
 
207
  # Verificar se houve erro no texto
208
  if texto.startswith("❌"):
@@ -239,7 +239,15 @@ def gerar_post_interface(tema, nicho, estilo, descricao_imagem, gerar_img):
239
  # INTERFACE GRADIO
240
  # ============================================
241
 
242
- with gr.Blocks(theme=gr.themes.Soft(), title="Gerador de Posts") as demo:
 
 
 
 
 
 
 
 
243
 
244
  gr.Markdown("""
245
  # 🚀 Gerador de Posts para Redes Sociais
@@ -266,6 +274,17 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Gerador de Posts") as demo:
266
  value=ESTILOS_DISPONIVEIS[0], # Adiciona valor padrão
267
  interactive=True
268
  )
 
 
 
 
 
 
 
 
 
 
 
269
 
270
  tema_input = gr.Textbox(
271
  label="Tema do Post",
@@ -343,9 +362,10 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Gerador de Posts") as demo:
343
  gerar_btn.click(
344
  fn=gerar_post_interface,
345
  # Ordem CORRETA para a função gerar_post_interface(tema, nicho, estilo, descricao_imagem, gerar_img)
346
- inputs=[tema_input, nicho_input, estilo_input, descricao_img_input, gerar_img_checkbox],
347
  # Ordem CORRETA para a função retornar (texto, imagem, status_final)
348
- outputs=[texto_output, imagem_output, status_output]
 
349
  )
350
 
351
  # ABA 2: Histórico
 
57
  # FUNÇÕES DE GERAÇÃO (adaptadas da Aula 8)
58
  # ============================================
59
 
60
+ def gerar_texto(tema, nicho, estilo, temperatura):
61
  """
62
  Gera texto usando API do Hugging Face
63
  """
 
90
  }
91
  ],
92
  "max_tokens": 350,
93
+ "temperature": temperatura,
94
  "stream": False
95
  }
96
 
 
181
  # FUNÇÃO PRINCIPAL PARA O GRADIO
182
  # ============================================
183
 
184
+ def gerar_post_interface(tema, nicho, estilo, descricao_imagem, gerar_img, temperatura):
185
  """
186
  Função principal que o Gradio chama quando usuário clica no botão.
187
 
 
202
 
203
 
204
  # Etapa 1: Gerar texto
205
+ texto = gerar_texto(tema, nicho, estilo, temperatura)
206
 
207
  # Verificar se houve erro no texto
208
  if texto.startswith("❌"):
 
239
  # INTERFACE GRADIO
240
  # ============================================
241
 
242
+ # Criar tema personalizado
243
+ tema_custom = gr.themes.Glass(
244
+ primary_hue="blue",
245
+ secondary_hue="amber",
246
+ neutral_hue="stone",
247
+ font=["Helvetica", "Georgia", "sans-serif"]
248
+ )
249
+
250
+ with gr.Blocks(theme=tema_custom, title="Gerador de Posts") as demo:
251
 
252
  gr.Markdown("""
253
  # 🚀 Gerador de Posts para Redes Sociais
 
274
  value=ESTILOS_DISPONIVEIS[0], # Adiciona valor padrão
275
  interactive=True
276
  )
277
+
278
+ # incremento para adicionar slider
279
+ temperatura_input = gr.Slider(
280
+ minimum=0.1,
281
+ maximum=1.0,
282
+ value=0.7,
283
+ step=0.1,
284
+ label="Criatividade (Temperature)",
285
+ info="Menor = mais conservador, Maior = mais criativo"
286
+ )
287
+
288
 
289
  tema_input = gr.Textbox(
290
  label="Tema do Post",
 
362
  gerar_btn.click(
363
  fn=gerar_post_interface,
364
  # Ordem CORRETA para a função gerar_post_interface(tema, nicho, estilo, descricao_imagem, gerar_img)
365
+ inputs=[tema_input, nicho_input, estilo_input, descricao_img_input, gerar_img_checkbox, temperatura_input],
366
  # Ordem CORRETA para a função retornar (texto, imagem, status_final)
367
+ outputs=[texto_output, imagem_output, status_output],
368
+ show_progress="full" # Barra de progresso completa
369
  )
370
 
371
  # ABA 2: Histórico