gbope commited on
Commit
ba42573
·
verified ·
1 Parent(s): 477e0b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -30
app.py CHANGED
@@ -122,7 +122,7 @@ def processar_documentos_para_whatsapp(titular_nascido_2010, categoria, modalida
122
  for nome, documentos in lista_completa:
123
  texto_final += formatar_documentos_para_whatsapp(nome, documentos)
124
 
125
- return texto_final.strip(), gr.update(visible=True), gr.update(visible=True) # Retorna texto, e torna visíveis o btn_copiar e status_copia
126
 
127
  def atualizar_lista_inclusos(titular_nascido_2010, categoria, modalidade, titular_carencia, dependentes_info):
128
  lista_inclusos = []
@@ -145,10 +145,11 @@ def atualizar_lista_inclusos(titular_nascido_2010, categoria, modalidade, titula
145
  # --- NOVA FUNÇÃO PARA RESETAR TODOS OS CAMPOS ---
146
  def limpar_tudo():
147
  return (
148
- gr.update(value="PF"), # categoria
149
  gr.update(choices=[], interactive=False, value=None), # modalidade (reinicia para vazio e desativado)
150
- gr.update(value=False), # titular_nascido_2010
151
- gr.update(value=False), # titular_carencia
 
152
  gr.update(value=None), # dep_tipo
153
  gr.update(value=False), # dep_nascido_2010
154
  gr.update(value=False), # dep_carencia
@@ -159,6 +160,19 @@ def limpar_tudo():
159
  gr.update(visible=False, value="") # status_copia (oculta e limpa o status da cópia)
160
  )
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  def criar_interface():
163
  with gr.Blocks(title="Documentos para Plano de Saúde", theme=gr.themes.Soft()) as app:
164
  gr.Markdown("# 📋 Documentos Necessários para Plano de Saúde")
@@ -166,23 +180,27 @@ def criar_interface():
166
 
167
  with gr.Row():
168
  with gr.Column():
169
- with gr.Group():
170
- gr.Markdown("### Titular")
171
- categoria = gr.Radio(
172
- choices=["PF", "CNPJ", "ADESAO"],
173
- label="Categoria do Titular",
174
- value="PF"
175
- )
176
- modalidade = gr.Dropdown(
177
- choices=[],
178
- label="Modalidade (se aplicável)",
179
- interactive=False
180
- )
181
- with gr.Row():
182
- titular_nascido_2010 = gr.Checkbox(label="Nasceu em 2010 ou depois?")
183
- titular_carencia = gr.Checkbox(label="Fará compra de carência?")
 
 
 
 
184
 
185
- with gr.Accordion("Adicionar Dependentes", open=True) as accordion_deps:
186
  with gr.Group():
187
  gr.Markdown("### Novo Dependente")
188
  dep_tipo = gr.Dropdown(
@@ -218,9 +236,9 @@ def criar_interface():
218
  )
219
  dependentes_info = gr.State([])
220
 
221
- with gr.Row(): # Agrupando botões de ação
222
  btn_submit = gr.Button("🔍 Gerar Lista de Documentos", variant="primary")
223
- btn_limpar = gr.Button("🧹 Limpar Tudo", variant="secondary") # Novo botão Limpar
224
 
225
  with gr.Column():
226
  output_textbox = gr.Textbox(
@@ -234,15 +252,15 @@ def criar_interface():
234
 
235
  def atualizar_modalidades(categoria):
236
  if categoria == "CNPJ":
237
- return gr.Dropdown(choices=["MEI", "OUTROS"], label="Modalidade CNPJ", interactive=True, value=None) # Resetar valor
238
  elif categoria == "ADESAO":
239
  return gr.Dropdown(
240
  choices=["ENTIDADE ABERTA", "ESTUDANTE", "TRABALHADOR", "PROFISSIONAL LIBERAL", "APOSENTADO"],
241
  label="Modalidade Adesão",
242
  interactive=True, value=None
243
- ) # Resetar valor
244
  else:
245
- return gr.Dropdown(choices=[], label="Modalidade (não aplicável)", interactive=False, value=None) # Resetar valor
246
 
247
  categoria.change(
248
  atualizar_modalidades,
@@ -277,7 +295,7 @@ def criar_interface():
277
  titular_carencia,
278
  dependentes_info
279
  ],
280
- outputs=[output_textbox, btn_copiar, status_copia] # Passamos status_copia também para que ele seja visível
281
  )
282
 
283
  btn_copiar.click(
@@ -302,30 +320,44 @@ def criar_interface():
302
  }
303
  """
304
  ).then(
305
- lambda: gr.update(visible=True), # Aqui o status_copia já foi tornado visível acima. Isso só garante que se por algum motivo ele sumisse, voltaria.
306
  None,
307
  status_copia
308
  )
309
 
310
- # --- CONEXÃO DO BOTÃO LIMPAR TUDO ---
311
  btn_limpar.click(
312
  limpar_tudo,
313
- inputs=None, # Não precisa de inputs para limpar
314
  outputs=[
315
  categoria,
316
  modalidade,
317
  titular_nascido_2010,
318
  titular_carencia,
 
319
  dep_tipo,
320
  dep_nascido_2010,
321
  dep_carencia,
322
  lista_inclusos,
323
- dependentes_info, # O State precisa ser resetado!
324
  output_textbox,
325
  btn_copiar,
326
  status_copia
327
  ]
328
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
 
330
  return app
331
 
 
122
  for nome, documentos in lista_completa:
123
  texto_final += formatar_documentos_para_whatsapp(nome, documentos)
124
 
125
+ return texto_final.strip(), gr.update(visible=True), gr.update(visible=True)
126
 
127
  def atualizar_lista_inclusos(titular_nascido_2010, categoria, modalidade, titular_carencia, dependentes_info):
128
  lista_inclusos = []
 
145
  # --- NOVA FUNÇÃO PARA RESETAR TODOS OS CAMPOS ---
146
  def limpar_tudo():
147
  return (
148
+ gr.update(value="PF", interactive=True), # categoria
149
  gr.update(choices=[], interactive=False, value=None), # modalidade (reinicia para vazio e desativado)
150
+ gr.update(value=False, interactive=True), # titular_nascido_2010
151
+ gr.update(value=False, interactive=True), # titular_carencia
152
+ gr.update(visible=True), # accordion_titular (volta a ser visível)
153
  gr.update(value=None), # dep_tipo
154
  gr.update(value=False), # dep_nascido_2010
155
  gr.update(value=False), # dep_carencia
 
160
  gr.update(visible=False, value="") # status_copia (oculta e limpa o status da cópia)
161
  )
162
 
163
+ # --- NOVA FUNÇÃO PARA CONFIRMAR TITULAR ---
164
+ def confirmar_titular():
165
+ # Isso torna os componentes do titular não interativos e esconde o botão de confirmar.
166
+ # O accordion "Adicionar Dependentes" pode ser aberto automaticamente aqui.
167
+ return (
168
+ gr.update(interactive=False), # categoria
169
+ gr.update(interactive=False), # modalidade
170
+ gr.update(interactive=False), # titular_nascido_2010
171
+ gr.update(interactive=False), # titular_carencia
172
+ gr.update(visible=False), # btn_confirmar_titular (esconde o próprio botão)
173
+ gr.Accordion(open=True) # Abre o accordion de dependentes
174
+ )
175
+
176
  def criar_interface():
177
  with gr.Blocks(title="Documentos para Plano de Saúde", theme=gr.themes.Soft()) as app:
178
  gr.Markdown("# 📋 Documentos Necessários para Plano de Saúde")
 
180
 
181
  with gr.Row():
182
  with gr.Column():
183
+ # Agrupamos os campos do titular em um gr.Group com um accordion
184
+ with gr.Accordion("Dados do Titular", open=True) as accordion_titular: # Novo accordion para o titular
185
+ with gr.Group(): # O antigo group
186
+ # gr.Markdown("### Titular") # Este Markdown já está no label do accordion
187
+ categoria = gr.Radio(
188
+ choices=["PF", "CNPJ", "ADESAO"],
189
+ label="Categoria do Titular",
190
+ value="PF"
191
+ )
192
+ modalidade = gr.Dropdown(
193
+ choices=[],
194
+ label="Modalidade (se aplicável)",
195
+ interactive=False
196
+ )
197
+ with gr.Row():
198
+ titular_nascido_2010 = gr.Checkbox(label="Nasceu em 2010 ou depois?")
199
+ titular_carencia = gr.Checkbox(label="Fará compra de carência?")
200
+ # --- NOVO BOTÃO DE CONFIRMAR TITULAR ---
201
+ btn_confirmar_titular = gr.Button("✅ Confirmar Dados do Titular", variant="primary")
202
 
203
+ with gr.Accordion("Adicionar Dependentes", open=False) as accordion_deps: # Começa fechado
204
  with gr.Group():
205
  gr.Markdown("### Novo Dependente")
206
  dep_tipo = gr.Dropdown(
 
236
  )
237
  dependentes_info = gr.State([])
238
 
239
+ with gr.Row():
240
  btn_submit = gr.Button("🔍 Gerar Lista de Documentos", variant="primary")
241
+ btn_limpar = gr.Button("🧹 Limpar Tudo", variant="secondary")
242
 
243
  with gr.Column():
244
  output_textbox = gr.Textbox(
 
252
 
253
  def atualizar_modalidades(categoria):
254
  if categoria == "CNPJ":
255
+ return gr.Dropdown(choices=["MEI", "OUTROS"], label="Modalidade CNPJ", interactive=True, value=None)
256
  elif categoria == "ADESAO":
257
  return gr.Dropdown(
258
  choices=["ENTIDADE ABERTA", "ESTUDANTE", "TRABALHADOR", "PROFISSIONAL LIBERAL", "APOSENTADO"],
259
  label="Modalidade Adesão",
260
  interactive=True, value=None
261
+ )
262
  else:
263
+ return gr.Dropdown(choices=[], label="Modalidade (não aplicável)", interactive=False, value=None)
264
 
265
  categoria.change(
266
  atualizar_modalidades,
 
295
  titular_carencia,
296
  dependentes_info
297
  ],
298
+ outputs=[output_textbox, btn_copiar, status_copia]
299
  )
300
 
301
  btn_copiar.click(
 
320
  }
321
  """
322
  ).then(
323
+ lambda: gr.update(visible=True),
324
  None,
325
  status_copia
326
  )
327
 
 
328
  btn_limpar.click(
329
  limpar_tudo,
330
+ inputs=None,
331
  outputs=[
332
  categoria,
333
  modalidade,
334
  titular_nascido_2010,
335
  titular_carencia,
336
+ accordion_titular, # Resetar o accordion do titular (visibilidade)
337
  dep_tipo,
338
  dep_nascido_2010,
339
  dep_carencia,
340
  lista_inclusos,
341
+ dependentes_info,
342
  output_textbox,
343
  btn_copiar,
344
  status_copia
345
  ]
346
  )
347
+
348
+ # --- CONEXÃO DO BOTÃO CONFIRMAR TITULAR ---
349
+ btn_confirmar_titular.click(
350
+ confirmar_titular,
351
+ inputs=None, # Não precisa de inputs para uma ação visual
352
+ outputs=[
353
+ categoria,
354
+ modalidade,
355
+ titular_nascido_2010,
356
+ titular_carencia,
357
+ btn_confirmar_titular, # Ocultar o próprio botão de confirmar
358
+ accordion_deps # Abrir o accordion de dependentes
359
+ ]
360
+ )
361
 
362
  return app
363