Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,41 +23,53 @@ CONTROVERSIAL_TOPICS = {
|
|
23 |
"Gálatas 3:28 - Não há judeu nem grego..."
|
24 |
]
|
25 |
},
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
|
29 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
try:
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
response += f"• {verse}\n"
|
43 |
-
|
44 |
-
response += "\nEstes versículos nos mostram diferentes aspectos deste tema. É importante estudá-los em seu contexto completo para uma melhor compreensão."
|
45 |
-
|
46 |
-
return response
|
47 |
-
else:
|
48 |
-
# Para perguntas gerais
|
49 |
-
response = f"Sua pergunta: {message}\n\n"
|
50 |
-
response += "Pesquisando nas escrituras...\n"
|
51 |
-
# Procurar por palavras-chave e retornar versículos relevantes
|
52 |
-
for topic, info in CONTROVERSIAL_TOPICS.items():
|
53 |
-
if any(word.lower() in message.lower() for word in topic.split()):
|
54 |
-
response += f"\nVersículos relacionados a {topic}:\n"
|
55 |
-
for verse in info['verses'][:2]:
|
56 |
-
response += f"• {verse}\n"
|
57 |
-
return response
|
58 |
|
59 |
except Exception as e:
|
60 |
-
|
|
|
61 |
|
62 |
# Interface Gradio
|
63 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
@@ -88,21 +100,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
88 |
with gr.Column(scale=1):
|
89 |
gr.Markdown("### 🔍 Temas para Explorar")
|
90 |
|
91 |
-
# Criar botões para cada tema
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
kwargs={"topic": topic}
|
101 |
-
)
|
102 |
|
103 |
# Eventos
|
104 |
msg.submit(process_message, [msg, chatbot], [chatbot])
|
105 |
-
clear.click(lambda:
|
106 |
|
107 |
gr.Markdown("""
|
108 |
### ℹ️ Como usar:
|
|
|
23 |
"Gálatas 3:28 - Não há judeu nem grego..."
|
24 |
]
|
25 |
},
|
26 |
+
"Aborto e Vida": {
|
27 |
+
"description": "Visão bíblica sobre a santidade da vida",
|
28 |
+
"verses": [
|
29 |
+
"Salmos 139:13-16 - Tu formaste o meu interior...",
|
30 |
+
"Jeremias 1:5 - Antes que te formasses...",
|
31 |
+
"Êxodo 20:13 - Não matarás"
|
32 |
+
]
|
33 |
+
}
|
34 |
}
|
35 |
|
36 |
+
def process_topic(topic, history):
|
37 |
+
"""Função específica para processar tópicos selecionados via botão"""
|
38 |
+
info = CONTROVERSIAL_TOPICS[topic]
|
39 |
+
response = f"""
|
40 |
+
📚 Tema: {topic}
|
41 |
+
|
42 |
+
📖 Descrição:
|
43 |
+
{info['description']}
|
44 |
+
|
45 |
+
✝️ Versículos Relevantes:
|
46 |
+
"""
|
47 |
+
for verse in info['verses']:
|
48 |
+
response += f"• {verse}\n"
|
49 |
+
|
50 |
+
response += "\nEstes versículos nos mostram diferentes aspectos deste tema. É importante estudá-los em seu contexto completo para uma melhor compreensão."
|
51 |
+
|
52 |
+
history.append((None, response))
|
53 |
+
return history
|
54 |
+
|
55 |
+
def process_message(message, history):
|
56 |
+
"""Função para processar mensagens digitadas pelo usuário"""
|
57 |
try:
|
58 |
+
response = f"Sua pergunta: {message}\n\n"
|
59 |
+
response += "Pesquisando nas escrituras...\n"
|
60 |
+
|
61 |
+
for topic, info in CONTROVERSIAL_TOPICS.items():
|
62 |
+
if any(word.lower() in message.lower() for word in topic.split()):
|
63 |
+
response += f"\nVersículos relacionados a {topic}:\n"
|
64 |
+
for verse in info['verses'][:2]:
|
65 |
+
response += f"• {verse}\n"
|
66 |
+
|
67 |
+
history.append((message, response))
|
68 |
+
return history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
except Exception as e:
|
71 |
+
history.append((message, f"Ocorreu um erro: {str(e)}"))
|
72 |
+
return history
|
73 |
|
74 |
# Interface Gradio
|
75 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
100 |
with gr.Column(scale=1):
|
101 |
gr.Markdown("### 🔍 Temas para Explorar")
|
102 |
|
103 |
+
# Criar botões para cada tema
|
104 |
+
for topic in CONTROVERSIAL_TOPICS.keys():
|
105 |
+
topic_btn = gr.Button(f"📚 {topic}")
|
106 |
+
# Criar uma closure para capturar o valor do tópico
|
107 |
+
topic_btn.click(
|
108 |
+
fn=lambda t=topic, h=None: process_topic(t, h if h else []),
|
109 |
+
inputs=[chatbot],
|
110 |
+
outputs=[chatbot]
|
111 |
+
)
|
|
|
|
|
112 |
|
113 |
# Eventos
|
114 |
msg.submit(process_message, [msg, chatbot], [chatbot])
|
115 |
+
clear.click(lambda: [], None, chatbot, queue=False)
|
116 |
|
117 |
gr.Markdown("""
|
118 |
### ℹ️ Como usar:
|