Spaces:
Running
Running
Update app.py
Browse filesCorreção de erros usando códigos atualizados para versão 4.x do Gradio
app.py
CHANGED
|
@@ -60,10 +60,11 @@ ESTILOS_DISPONIVEIS = [
|
|
| 60 |
"Tutorial/Passo a Passo",
|
| 61 |
]
|
| 62 |
|
|
|
|
| 63 |
FORMATO_CONFIGS = {
|
| 64 |
"Instagram (Post)": {"tamanho": "100-150 palavras", "estrutura": "gancho inicial + desenvolvimento + call-to-action", "tom_adicional": "próximo, empático e motivador", "max_tokens": 350, "limite_palavras_ia": "150 palavras", "hashtags": "Incluir 4-5 hashtags relevantes no final. Incluir no máximo 3 emojis relevantes no texto."},
|
| 65 |
"Twitter/X (Curto)": {"tamanho": "Até 280 caracteres", "estrutura": "frase de impacto + link/hashtag", "tom_adicional": "direto e conciso, ideal para tweets", "max_tokens": 150, "limite_palavras_ia": "280 caracteres", "hashtags": "Incluir no máximo 2 hashtags."},
|
| 66 |
-
"LinkedIn (Artigo)": {"tamanho": "250-400 palavras", "estrutura": "título chamativo + desenvolvimento profissional + reflexão", "tom_adicional": "profissional e autoritário
|
| 67 |
}
|
| 68 |
|
| 69 |
# Variável global para armazenar o histórico de sessão (agora é um cache)
|
|
@@ -474,12 +475,8 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts e Chatbot") as demo:
|
|
| 474 |
### Powered by Hugging Face, Gradio e Llama 3.1
|
| 475 |
""")
|
| 476 |
|
| 477 |
-
theme_mode = gr.Radio(
|
| 478 |
-
|
| 479 |
-
label="Modo de Visualização",
|
| 480 |
-
value="light",
|
| 481 |
-
interactive=True
|
| 482 |
-
)
|
| 483 |
|
| 484 |
with gr.Tabs():
|
| 485 |
with gr.TabItem("✨ Gerar Post"):
|
|
@@ -647,28 +644,17 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts e Chatbot") as demo:
|
|
| 647 |
chatbot=chatbot_para_interface, # Passando o componente chatbot customizado
|
| 648 |
textbox=gr.Textbox(placeholder="Digite sua mensagem aqui...", scale=7),
|
| 649 |
submit_btn="Enviar",
|
| 650 |
-
|
| 651 |
)
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
with gr.Blocks() as demo:
|
| 662 |
-
gr.Markdown("### 🤖 Assistente Virtual")
|
| 663 |
-
gr.Markdown("Converse com o Llama 3.1 para obter ajuda e insights.")
|
| 664 |
-
|
| 665 |
-
chatbot_display = gr.Chatbot(height=500, type="messages")
|
| 666 |
-
entrada = gr.Textbox(placeholder="Digite sua mensagem aqui...", scale=7)
|
| 667 |
-
enviar_btn = gr.Button("Enviar")
|
| 668 |
-
limpar_btn = gr.Button("Limpar")
|
| 669 |
-
|
| 670 |
-
enviar_btn.click(fn=responder_chat, inputs=[entrada, chatbot_display], outputs=[chatbot_display])
|
| 671 |
-
limpar_btn.click(fn=lambda: [], inputs=[], outputs=[chatbot_display])
|
| 672 |
|
| 673 |
# ABA 2: Histórico (Exibe o Dataframe)
|
| 674 |
with gr.TabItem("📚 Histórico de Posts"):
|
|
@@ -746,3 +732,4 @@ with gr.Blocks(theme=custom_theme, title="Gerador de Posts e Chatbot") as demo:
|
|
| 746 |
# Lançar aplicação
|
| 747 |
if __name__ == "__main__":
|
| 748 |
demo.launch()
|
|
|
|
|
|
| 60 |
"Tutorial/Passo a Passo",
|
| 61 |
]
|
| 62 |
|
| 63 |
+
# CORRIGIDO: O dicionário do LinkedIn estava quebrado
|
| 64 |
FORMATO_CONFIGS = {
|
| 65 |
"Instagram (Post)": {"tamanho": "100-150 palavras", "estrutura": "gancho inicial + desenvolvimento + call-to-action", "tom_adicional": "próximo, empático e motivador", "max_tokens": 350, "limite_palavras_ia": "150 palavras", "hashtags": "Incluir 4-5 hashtags relevantes no final. Incluir no máximo 3 emojis relevantes no texto."},
|
| 66 |
"Twitter/X (Curto)": {"tamanho": "Até 280 caracteres", "estrutura": "frase de impacto + link/hashtag", "tom_adicional": "direto e conciso, ideal para tweets", "max_tokens": 150, "limite_palavras_ia": "280 caracteres", "hashtags": "Incluir no máximo 2 hashtags."},
|
| 67 |
+
"LinkedIn (Artigo)": {"tamanho": "250-400 palavras", "estrutura": "título chamativo + desenvolvimento profissional + reflexão", "tom_adicional": "profissional e autoritário, focado em insights", "max_tokens": 700, "limite_palavras_ia": "400 palavras", "hashtags": "Incluir 3-4 hashtags profissionais no final."},
|
| 68 |
}
|
| 69 |
|
| 70 |
# Variável global para armazenar o histórico de sessão (agora é um cache)
|
|
|
|
| 475 |
### Powered by Hugging Face, Gradio e Llama 3.1
|
| 476 |
""")
|
| 477 |
|
| 478 |
+
# REMOVIDO: theme_mode = gr.Radio(...) não é mais a forma padrão do Gradio 4.x
|
| 479 |
+
# e não estava conectado a nenhum evento.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
with gr.Tabs():
|
| 482 |
with gr.TabItem("✨ Gerar Post"):
|
|
|
|
| 644 |
chatbot=chatbot_para_interface, # Passando o componente chatbot customizado
|
| 645 |
textbox=gr.Textbox(placeholder="Digite sua mensagem aqui...", scale=7),
|
| 646 |
submit_btn="Enviar",
|
| 647 |
+
clear_btn="Limpar Conversa", # CORRIGIDO: Botão de limpar correto para ChatInterface
|
| 648 |
)
|
| 649 |
+
|
| 650 |
+
# --- INÍCIO DO BLOCO DE ERRO REMOVIDO ---
|
| 651 |
+
# O bloco abaixo era uma definição duplicada e conflitante
|
| 652 |
+
# e continha um gr.Blocks() aninhado, o que é ilegal.
|
| 653 |
+
|
| 654 |
+
# def responder_chat(mensagem, historico): ...
|
| 655 |
+
# with gr.Blocks() as demo: ...
|
| 656 |
+
|
| 657 |
+
# --- FIM DO BLOCO DE ERRO REMOVIDO ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
|
| 659 |
# ABA 2: Histórico (Exibe o Dataframe)
|
| 660 |
with gr.TabItem("📚 Histórico de Posts"):
|
|
|
|
| 732 |
# Lançar aplicação
|
| 733 |
if __name__ == "__main__":
|
| 734 |
demo.launch()
|
| 735 |
+
|