Spaces:
Running
Running
Update interface.py
Browse files- interface.py +49 -32
interface.py
CHANGED
@@ -1,33 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
-
from ai_logic import
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
# CSS personalizado
|
5 |
css_customizado = """
|
6 |
.gradio-container { max-width: 1400px !important; margin: 0 auto; width: 99%; }
|
7 |
.gr-textbox textarea { font-size: 14px !important; line-height: 1.5 !important; }
|
|
|
|
|
|
|
|
|
8 |
.modelo-dropdown { margin-bottom: 15px !important; }
|
9 |
"""
|
10 |
|
11 |
def criar_interface():
|
12 |
-
"
|
13 |
-
|
14 |
-
with gr.Blocks(title="Dr. Aldo Henrique - Chat IA", theme=gr.themes.Soft(), css=css_customizado) as interface:
|
15 |
# Cabeçalho
|
16 |
gr.HTML("""
|
17 |
-
<div class="titulo-principal"
|
18 |
-
<h1>🤖 Dr. Aldo Henrique - Foco em TI com diferentes modelos de IA</h1>
|
19 |
<p style="font-size: 14px; opacity: 0.9;">Conhecimento enriquecido com o conteúdo do <a href="https://aldohenrique.com.br/" style="color: white; text-decoration: underline;">Blog do Prof. Dr. Aldo Henrique</a></p>
|
20 |
</div>
|
21 |
""")
|
22 |
|
23 |
-
|
24 |
|
25 |
with gr.Row():
|
26 |
-
entrada = gr.Textbox(
|
27 |
-
placeholder="Digite sua pergunta aqui e pressione Enter...",
|
28 |
-
show_label=False,
|
29 |
-
lines=3
|
30 |
-
)
|
31 |
modelo_select = gr.Dropdown(
|
32 |
choices=list(MODELS.keys()),
|
33 |
value=DEFAULT_MODEL,
|
@@ -36,25 +38,41 @@ def criar_interface():
|
|
36 |
elem_classes="modelo-dropdown"
|
37 |
)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
inputs=[
|
53 |
-
outputs=[
|
54 |
show_progress=True
|
55 |
-
)
|
56 |
|
57 |
-
#
|
58 |
with gr.Accordion("⚙️ Controle do Conhecimento (RAG)", open=False):
|
59 |
status_rag = gr.Textbox(label="Status do Retreino", interactive=False)
|
60 |
botao_retreinar = gr.Button("🔄 Atualizar Conhecimento do Blog", variant="stop")
|
@@ -75,10 +93,10 @@ def criar_interface():
|
|
75 |
["Qual a sua opinião sobre o uso de ponteiros em C++ moderno, baseada no seu blog?", "Mistral 7B"],
|
76 |
["Resuma o que você escreveu sobre machine learning no seu blog.", "Zephyr 7B"],
|
77 |
],
|
78 |
-
inputs=[
|
79 |
)
|
80 |
|
81 |
-
# Status
|
82 |
with gr.Accordion("🔧 Status da API", open=False):
|
83 |
status_api = gr.Textbox(label="Status dos Modelos", interactive=False, lines=8)
|
84 |
|
@@ -97,5 +115,4 @@ def criar_interface():
|
|
97 |
return interface
|
98 |
|
99 |
def configurar_interface():
|
100 |
-
"""Configura e retorna a interface pronta para lançamento"""
|
101 |
return criar_interface()
|
|
|
1 |
import gradio as gr
|
2 |
+
from ai_logic import (
|
3 |
+
responder_como_aldo,
|
4 |
+
build_and_save_vector_store,
|
5 |
+
testar_todos_modelos,
|
6 |
+
MODELS,
|
7 |
+
DEFAULT_MODEL
|
8 |
+
)
|
9 |
|
|
|
10 |
css_customizado = """
|
11 |
.gradio-container { max-width: 1400px !important; margin: 0 auto; width: 99%; }
|
12 |
.gr-textbox textarea { font-size: 14px !important; line-height: 1.5 !important; }
|
13 |
+
.resposta-container { background-color: #ffffff !important; color: #1a1a1a !important; border: 1px solid #e0e0e0 !important; border-radius: 20px !important; padding: 20px !important; margin: 20px 0 !important; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important; }
|
14 |
+
.resposta-container pre code { color: #1a1a1a !important; background-color: #f8f9fa !important; }
|
15 |
+
.pergunta-container { background-color: #f0f8ff !important; border-radius: 8px !important; padding: 15px !important; }
|
16 |
+
.titulo-principal { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; color: white !important; padding: 20px !important; border-radius: 10px !important; margin-bottom: 20px !important; text-align: center !important; }
|
17 |
.modelo-dropdown { margin-bottom: 15px !important; }
|
18 |
"""
|
19 |
|
20 |
def criar_interface():
|
21 |
+
with gr.Blocks(title="Dr. Aldo Henrique - API Externa", theme=gr.themes.Soft(), css=css_customizado) as interface:
|
|
|
|
|
22 |
# Cabeçalho
|
23 |
gr.HTML("""
|
24 |
+
<div class="titulo-principal">
|
25 |
+
<h1>🤖 Dr. Aldo Henrique - Foco em TI com diferentes modelos de IA </h1>
|
26 |
<p style="font-size: 14px; opacity: 0.9;">Conhecimento enriquecido com o conteúdo do <a href="https://aldohenrique.com.br/" style="color: white; text-decoration: underline;">Blog do Prof. Dr. Aldo Henrique</a></p>
|
27 |
</div>
|
28 |
""")
|
29 |
|
30 |
+
chatbot = gr.Chatbot(label="💬 Chat com Dr. Aldo", elem_id="chat")
|
31 |
|
32 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
33 |
modelo_select = gr.Dropdown(
|
34 |
choices=list(MODELS.keys()),
|
35 |
value=DEFAULT_MODEL,
|
|
|
38 |
elem_classes="modelo-dropdown"
|
39 |
)
|
40 |
|
41 |
+
with gr.Row():
|
42 |
+
user_input = gr.Textbox(
|
43 |
+
show_label=False,
|
44 |
+
placeholder="Digite sua pergunta e pressione Enter ou clique em Enviar",
|
45 |
+
lines=1,
|
46 |
+
elem_id="entrada_usuario"
|
47 |
+
)
|
48 |
+
enviar_btn = gr.Button("Enviar", variant="primary")
|
49 |
+
|
50 |
+
estado_chat = gr.State([])
|
51 |
+
|
52 |
+
def responder(mensagens, user_msg, modelo):
|
53 |
+
mensagens = mensagens or []
|
54 |
+
mensagens.append(("Usuário", user_msg))
|
55 |
+
resposta_html = "<i>Dr. Aldo Henrique está digitando...</i>"
|
56 |
+
yield mensagens + [("Dr. Aldo", resposta_html)], "" # Mostra o typing
|
57 |
+
resposta_final = responder_como_aldo(user_msg, modelo)
|
58 |
+
mensagens.append(("Dr. Aldo", resposta_final))
|
59 |
+
yield mensagens, ""
|
60 |
+
|
61 |
+
enviar_btn.click(
|
62 |
+
fn=responder,
|
63 |
+
inputs=[estado_chat, user_input, modelo_select],
|
64 |
+
outputs=[chatbot, user_input],
|
65 |
+
show_progress=True
|
66 |
+
)
|
67 |
|
68 |
+
user_input.submit(
|
69 |
+
fn=responder,
|
70 |
+
inputs=[estado_chat, user_input, modelo_select],
|
71 |
+
outputs=[chatbot, user_input],
|
72 |
show_progress=True
|
73 |
+
)
|
74 |
|
75 |
+
# RAG
|
76 |
with gr.Accordion("⚙️ Controle do Conhecimento (RAG)", open=False):
|
77 |
status_rag = gr.Textbox(label="Status do Retreino", interactive=False)
|
78 |
botao_retreinar = gr.Button("🔄 Atualizar Conhecimento do Blog", variant="stop")
|
|
|
93 |
["Qual a sua opinião sobre o uso de ponteiros em C++ moderno, baseada no seu blog?", "Mistral 7B"],
|
94 |
["Resuma o que você escreveu sobre machine learning no seu blog.", "Zephyr 7B"],
|
95 |
],
|
96 |
+
inputs=[user_input, modelo_select]
|
97 |
)
|
98 |
|
99 |
+
# Status API
|
100 |
with gr.Accordion("🔧 Status da API", open=False):
|
101 |
status_api = gr.Textbox(label="Status dos Modelos", interactive=False, lines=8)
|
102 |
|
|
|
115 |
return interface
|
116 |
|
117 |
def configurar_interface():
|
|
|
118 |
return criar_interface()
|