Spaces:
Running
Running
Update app.py
Browse filesCorreção do botão Copiar texto
app.py
CHANGED
|
@@ -974,7 +974,7 @@ def gerar_post_interface(tema, nicho, estilo, formato, usar_cache, favorito_chec
|
|
| 974 |
progress=gr.Progress()):
|
| 975 |
"""
|
| 976 |
Função principal unificada, com Cache, Analytics, Favoritos e Geração Avançada.
|
| 977 |
-
Retorna
|
| 978 |
"""
|
| 979 |
|
| 980 |
analytics_display = gerar_relatorio_analytics() # Carregar estado atual
|
|
@@ -985,8 +985,8 @@ def gerar_post_interface(tema, nicho, estilo, formato, usar_cache, favorito_chec
|
|
| 985 |
progress(0.1, desc="✅ Validando...")
|
| 986 |
if not tema or len(tema.strip()) < 3:
|
| 987 |
status_final = criar_alerta('error', '⚠️ Digite um tema válido!')
|
| 988 |
-
# Retorna
|
| 989 |
-
return ("", None, status_final, 0, 0, 0, analytics_display,
|
| 990 |
time.sleep(0.3)
|
| 991 |
|
| 992 |
# 1. Lógica de Cache
|
|
@@ -1017,7 +1017,7 @@ def gerar_post_interface(tema, nicho, estilo, formato, usar_cache, favorito_chec
|
|
| 1017 |
}
|
| 1018 |
atualizar_historico(history_entry)
|
| 1019 |
|
| 1020 |
-
return (texto, imagem, status_final, palavras, caracteres, hashtags, analytics_display,
|
| 1021 |
|
| 1022 |
print("Cache miss ou cache desativado.")
|
| 1023 |
progress(0.3, desc="🤖 Gerando texto (Llama 3.1)...")
|
|
@@ -1027,7 +1027,7 @@ def gerar_post_interface(tema, nicho, estilo, formato, usar_cache, favorito_chec
|
|
| 1027 |
|
| 1028 |
if texto.startswith("❌"):
|
| 1029 |
status_final = criar_alerta('error', f'{texto}')
|
| 1030 |
-
return (texto, None, status_final, 0, 0, 0, analytics_display,
|
| 1031 |
|
| 1032 |
progress(0.5, desc="✅ Texto pronto!")
|
| 1033 |
time.sleep(0.5)
|
|
@@ -1090,7 +1090,7 @@ def gerar_post_interface(tema, nicho, estilo, formato, usar_cache, favorito_chec
|
|
| 1090 |
|
| 1091 |
progress(1.0, desc="🎉 Pronto!")
|
| 1092 |
|
| 1093 |
-
return (texto, imagem, status_final, palavras, caracteres, hashtags, analytics_display,
|
| 1094 |
|
| 1095 |
|
| 1096 |
# ============================================
|
|
@@ -1249,9 +1249,10 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts e Chatbot (Completo)"
|
|
| 1249 |
editor_locked = gr.State(True)
|
| 1250 |
refinar_btn = gr.Button("✏️ Refinar Post")
|
| 1251 |
|
|
|
|
|
|
|
| 1252 |
with gr.Row():
|
| 1253 |
-
# CORREÇÃO:
|
| 1254 |
-
copiar_btn = gr.Button("📋 Copiar Texto", variant="secondary")
|
| 1255 |
limpar_btn = gr.Button("🧹 Limpar Tudo", variant="stop")
|
| 1256 |
|
| 1257 |
gr.Markdown("") # Espaçamento
|
|
@@ -1498,7 +1499,7 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts e Chatbot (Completo)"
|
|
| 1498 |
texto_output, imagem_output, status_output,
|
| 1499 |
palavras_output, caracteres_output, hashtags_output,
|
| 1500 |
analytics_display,
|
| 1501 |
-
texto_output, # Saída duplicada para o copiar_btn
|
| 1502 |
editor_locked, texto_output, refinar_btn
|
| 1503 |
]
|
| 1504 |
|
|
@@ -1510,48 +1511,8 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts e Chatbot (Completo)"
|
|
| 1510 |
show_progress="full"
|
| 1511 |
)
|
| 1512 |
|
| 1513 |
-
# Botão copiar (
|
| 1514 |
-
|
| 1515 |
-
fn=copiar_feedback,
|
| 1516 |
-
inputs=[texto_output],
|
| 1517 |
-
outputs=[status_output],
|
| 1518 |
-
_js="""
|
| 1519 |
-
(texto_do_output) => {
|
| 1520 |
-
if (navigator.clipboard) {
|
| 1521 |
-
navigator.clipboard.writeText(texto_do_output)
|
| 1522 |
-
.then(() => {
|
| 1523 |
-
console.log("Texto copiado com sucesso (navigator.clipboard)");
|
| 1524 |
-
})
|
| 1525 |
-
.catch(err => {
|
| 1526 |
-
console.error("Falha ao copiar (navigator.clipboard), tentando fallback...", err);
|
| 1527 |
-
// Fallback: Tentar execCommand
|
| 1528 |
-
const elem = document.createElement('textarea');
|
| 1529 |
-
elem.value = texto_do_output;
|
| 1530 |
-
elem.style.position = 'absolute';
|
| 1531 |
-
elem.style.left = '-9999px';
|
| 1532 |
-
document.body.appendChild(elem);
|
| 1533 |
-
elem.select();
|
| 1534 |
-
document.execCommand('copy');
|
| 1535 |
-
document.body.removeChild(elem);
|
| 1536 |
-
console.log("Texto copiado com sucesso (execCommand fallback)");
|
| 1537 |
-
});
|
| 1538 |
-
} else {
|
| 1539 |
-
// Fallback final para navegadores muito antigos
|
| 1540 |
-
const elem = document.createElement('textarea');
|
| 1541 |
-
elem.value = texto_do_output;
|
| 1542 |
-
elem.style.position = 'absolute';
|
| 1543 |
-
elem.style.left = '-9999px';
|
| 1544 |
-
document.body.appendChild(elem);
|
| 1545 |
-
elem.select();
|
| 1546 |
-
document.execCommand('copy');
|
| 1547 |
-
document.body.removeChild(elem);
|
| 1548 |
-
console.log("Texto copiado com sucesso (execCommand fallback 2)");
|
| 1549 |
-
}
|
| 1550 |
-
// Retorna o valor para a função Python (copiar_feedback)
|
| 1551 |
-
return texto_do_output;
|
| 1552 |
-
}
|
| 1553 |
-
"""
|
| 1554 |
-
)
|
| 1555 |
|
| 1556 |
# Lista de outputs para o botão Limpar
|
| 1557 |
limpar_outputs = [
|
|
|
|
| 974 |
progress=gr.Progress()):
|
| 975 |
"""
|
| 976 |
Função principal unificada, com Cache, Analytics, Favoritos e Geração Avançada.
|
| 977 |
+
Retorna 10 valores para a UI.
|
| 978 |
"""
|
| 979 |
|
| 980 |
analytics_display = gerar_relatorio_analytics() # Carregar estado atual
|
|
|
|
| 985 |
progress(0.1, desc="✅ Validando...")
|
| 986 |
if not tema or len(tema.strip()) < 3:
|
| 987 |
status_final = criar_alerta('error', '⚠️ Digite um tema válido!')
|
| 988 |
+
# Retorna 10 valores
|
| 989 |
+
return ("", None, status_final, 0, 0, 0, analytics_display, True, gr.Textbox(interactive=False), gr.Button(value="✏️ Refinar Post"))
|
| 990 |
time.sleep(0.3)
|
| 991 |
|
| 992 |
# 1. Lógica de Cache
|
|
|
|
| 1017 |
}
|
| 1018 |
atualizar_historico(history_entry)
|
| 1019 |
|
| 1020 |
+
return (texto, imagem, status_final, palavras, caracteres, hashtags, analytics_display, True, gr.Textbox(interactive=False), gr.Button(value="✏️ Refinar Post"))
|
| 1021 |
|
| 1022 |
print("Cache miss ou cache desativado.")
|
| 1023 |
progress(0.3, desc="🤖 Gerando texto (Llama 3.1)...")
|
|
|
|
| 1027 |
|
| 1028 |
if texto.startswith("❌"):
|
| 1029 |
status_final = criar_alerta('error', f'{texto}')
|
| 1030 |
+
return (texto, None, status_final, 0, 0, 0, analytics_display, True, gr.Textbox(interactive=False), gr.Button(value="✏️ Refinar Post"))
|
| 1031 |
|
| 1032 |
progress(0.5, desc="✅ Texto pronto!")
|
| 1033 |
time.sleep(0.5)
|
|
|
|
| 1090 |
|
| 1091 |
progress(1.0, desc="🎉 Pronto!")
|
| 1092 |
|
| 1093 |
+
return (texto, imagem, status_final, palavras, caracteres, hashtags, analytics_display, True, gr.Textbox(interactive=False), gr.Button(value="✏️ Refinar Post"))
|
| 1094 |
|
| 1095 |
|
| 1096 |
# ============================================
|
|
|
|
| 1249 |
editor_locked = gr.State(True)
|
| 1250 |
refinar_btn = gr.Button("✏️ Refinar Post")
|
| 1251 |
|
| 1252 |
+
gr.Markdown("ℹ️ *Use o ícone de prancheta (📋) no canto superior direito da caixa de texto para copiar o conteúdo.*")
|
| 1253 |
+
|
| 1254 |
with gr.Row():
|
| 1255 |
+
# CORREÇÃO: Removido o botão de cópia problemático
|
|
|
|
| 1256 |
limpar_btn = gr.Button("🧹 Limpar Tudo", variant="stop")
|
| 1257 |
|
| 1258 |
gr.Markdown("") # Espaçamento
|
|
|
|
| 1499 |
texto_output, imagem_output, status_output,
|
| 1500 |
palavras_output, caracteres_output, hashtags_output,
|
| 1501 |
analytics_display,
|
| 1502 |
+
# texto_output, # Saída duplicada para o copiar_btn removida
|
| 1503 |
editor_locked, texto_output, refinar_btn
|
| 1504 |
]
|
| 1505 |
|
|
|
|
| 1511 |
show_progress="full"
|
| 1512 |
)
|
| 1513 |
|
| 1514 |
+
# Botão copiar (sem _js, removido)
|
| 1515 |
+
# O show_copy_button=True no texto_output cuidará disso.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1516 |
|
| 1517 |
# Lista de outputs para o botão Limpar
|
| 1518 |
limpar_outputs = [
|