Update app.py
Browse files
app.py
CHANGED
|
@@ -143,6 +143,7 @@ def atualizar_lista_inclusos(titular_nascido_2010, categoria, modalidade, titula
|
|
| 143 |
return lista_inclusos
|
| 144 |
|
| 145 |
def limpar_texto_para_copiar(texto):
|
|
|
|
| 146 |
texto_limpo = re.sub('<[^<]+?>', '', texto)
|
| 147 |
texto_limpo = texto_limpo.replace('</ul>', '\n').replace('</li>', '\n')
|
| 148 |
texto_limpo = re.sub('\n+', '\n', texto_limpo).strip()
|
|
@@ -210,10 +211,12 @@ def criar_interface():
|
|
| 210 |
btn_submit = gr.Button("🔍 Gerar Lista de Documentos", variant="primary")
|
| 211 |
|
| 212 |
with gr.Column():
|
| 213 |
-
output
|
| 214 |
-
|
|
|
|
|
|
|
| 215 |
btn_copiar = gr.Button("📋 Copiar Lista")
|
| 216 |
-
status_copia = gr.Textbox(label="Status", interactive=False, visible=False)
|
| 217 |
|
| 218 |
def atualizar_modalidades(categoria):
|
| 219 |
if categoria == "CNPJ":
|
|
@@ -260,20 +263,20 @@ def criar_interface():
|
|
| 260 |
titular_carencia,
|
| 261 |
dependentes_info
|
| 262 |
],
|
| 263 |
-
outputs=
|
| 264 |
).then(
|
| 265 |
limpar_texto_para_copiar,
|
| 266 |
-
inputs=output
|
| 267 |
-
outputs=texto_para_copiar
|
| 268 |
)
|
| 269 |
|
| 270 |
btn_copiar.click(
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
js="""
|
| 275 |
async () => {
|
| 276 |
-
const texto = document.
|
| 277 |
try {
|
| 278 |
await navigator.clipboard.writeText(texto);
|
| 279 |
return "✅ Copiado para área de transferência!";
|
|
@@ -293,7 +296,7 @@ def criar_interface():
|
|
| 293 |
None,
|
| 294 |
status_copia
|
| 295 |
)
|
| 296 |
-
|
| 297 |
return app
|
| 298 |
|
| 299 |
# Criação e lançamento da interface
|
|
|
|
| 143 |
return lista_inclusos
|
| 144 |
|
| 145 |
def limpar_texto_para_copiar(texto):
|
| 146 |
+
# This function is good as is, it cleans the HTML for copying
|
| 147 |
texto_limpo = re.sub('<[^<]+?>', '', texto)
|
| 148 |
texto_limpo = texto_limpo.replace('</ul>', '\n').replace('</li>', '\n')
|
| 149 |
texto_limpo = re.sub('\n+', '\n', texto_limpo).strip()
|
|
|
|
| 211 |
btn_submit = gr.Button("🔍 Gerar Lista de Documentos", variant="primary")
|
| 212 |
|
| 213 |
with gr.Column():
|
| 214 |
+
# Display output as HTML
|
| 215 |
+
output_html = gr.HTML(label="Documentos Necessários")
|
| 216 |
+
# This textbox will hold the *clean text* for copying
|
| 217 |
+
texto_para_copiar = gr.Textbox(label="Texto para Copiar", interactive=False, lines=10, visible=True, elem_id="texto-para-copiar")
|
| 218 |
btn_copiar = gr.Button("📋 Copiar Lista")
|
| 219 |
+
status_copia = gr.Textbox(label="Status da Cópia", interactive=False, visible=False)
|
| 220 |
|
| 221 |
def atualizar_modalidades(categoria):
|
| 222 |
if categoria == "CNPJ":
|
|
|
|
| 263 |
titular_carencia,
|
| 264 |
dependentes_info
|
| 265 |
],
|
| 266 |
+
outputs=output_html # Output to the HTML display
|
| 267 |
).then(
|
| 268 |
limpar_texto_para_copiar,
|
| 269 |
+
inputs=output_html, # Use the HTML output as input for cleaning
|
| 270 |
+
outputs=texto_para_copiar # Populate the hidden textbox with clean text
|
| 271 |
)
|
| 272 |
|
| 273 |
btn_copiar.click(
|
| 274 |
+
None, # No Python function needed here
|
| 275 |
+
None, # No Python inputs needed
|
| 276 |
+
status_copia,
|
| 277 |
js="""
|
| 278 |
async () => {
|
| 279 |
+
const texto = document.getElementById("texto-para-copiar").querySelector("textarea").value;
|
| 280 |
try {
|
| 281 |
await navigator.clipboard.writeText(texto);
|
| 282 |
return "✅ Copiado para área de transferência!";
|
|
|
|
| 296 |
None,
|
| 297 |
status_copia
|
| 298 |
)
|
| 299 |
+
|
| 300 |
return app
|
| 301 |
|
| 302 |
# Criação e lançamento da interface
|