Spaces:
Running
Running
Update interface.py
Browse files- interface.py +81 -43
interface.py
CHANGED
@@ -8,36 +8,84 @@ from ai_logic import (
|
|
8 |
)
|
9 |
|
10 |
css_customizado = """
|
11 |
-
.gradio-container {
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
.
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
#entrada_usuario textarea {
|
22 |
-
color: white !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
}
|
24 |
-
.message-content{font-size: larger; color: white !important; background-color: #1a1a1a !important; }
|
25 |
"""
|
26 |
|
27 |
def criar_interface():
|
28 |
with gr.Blocks(title="Dr. Aldo Henrique - API Externa", theme=gr.themes.Soft(), css=css_customizado) as interface:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
|
40 |
-
with gr.Row():
|
41 |
modelo_select = gr.Dropdown(
|
42 |
choices=list(MODELS.keys()),
|
43 |
value=DEFAULT_MODEL,
|
@@ -46,37 +94,32 @@ def criar_interface():
|
|
46 |
elem_classes="modelo-dropdown"
|
47 |
)
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
|
|
58 |
def responder(chat_history, user_msg, modelo):
|
59 |
if not user_msg.strip():
|
60 |
return chat_history, ""
|
61 |
-
|
62 |
-
# Adiciona a mensagem do usuário e uma resposta temporária
|
63 |
chat_history = chat_history + [[user_msg, "Dr. Aldo Henrique está digitando..."]]
|
64 |
yield chat_history, ""
|
65 |
-
|
66 |
-
# Gera a resposta real
|
67 |
resposta_final = responder_como_aldo(user_msg, modelo)
|
68 |
-
|
69 |
-
# Atualiza com a resposta final
|
70 |
chat_history[-1][1] = resposta_final
|
71 |
yield chat_history, ""
|
72 |
|
|
|
73 |
enviar_btn.click(
|
74 |
fn=responder,
|
75 |
inputs=[chatbot, user_input, modelo_select],
|
76 |
outputs=[chatbot, user_input],
|
77 |
show_progress=True
|
78 |
)
|
79 |
-
|
80 |
user_input.submit(
|
81 |
fn=responder,
|
82 |
inputs=[chatbot, user_input, modelo_select],
|
@@ -118,12 +161,7 @@ def criar_interface():
|
|
118 |
### Sobre o Dr. Aldo Henrique:
|
119 |
- **Especialidade**: Linguagens C, Java, Desenvolvimento Web, Inteligência Artificial
|
120 |
- **Conhecimento Adicional**: Conteúdo do blog aldohenrique.com.br
|
121 |
-
|
122 |
-
### Dicas para melhores respostas:
|
123 |
-
- Faça perguntas específicas sobre o conteúdo do blog para ver o RAG em ação!
|
124 |
-
- Peça resumos ou opiniões sobre temas que o professor aborda.
|
125 |
""")
|
126 |
-
|
127 |
|
128 |
# Foco automático no campo de texto ao abrir
|
129 |
gr.HTML("""
|
@@ -135,7 +173,7 @@ def criar_interface():
|
|
135 |
}
|
136 |
});
|
137 |
</script>
|
138 |
-
""")
|
139 |
|
140 |
return interface
|
141 |
|
|
|
8 |
)
|
9 |
|
10 |
css_customizado = """
|
11 |
+
.gradio-container {
|
12 |
+
max-width: 1400px !important;
|
13 |
+
margin: 0 auto;
|
14 |
+
width: 99%;
|
15 |
+
}
|
16 |
+
|
17 |
+
.conteudo-principal {
|
18 |
+
height: 100vh;
|
19 |
+
display: flex;
|
20 |
+
flex-direction: column;
|
21 |
+
justify-content: space-between;
|
22 |
+
padding: 10px;
|
23 |
+
}
|
24 |
+
|
25 |
+
.gr-textbox textarea {
|
26 |
+
font-size: 14px !important;
|
27 |
+
line-height: 1.5 !important;
|
28 |
+
}
|
29 |
+
|
30 |
+
.resposta-container {
|
31 |
+
background-color: #ffffff !important;
|
32 |
+
color: #1a1a1a !important;
|
33 |
+
border: 1px solid #e0e0e0 !important;
|
34 |
+
border-radius: 20px !important;
|
35 |
+
padding: 20px !important;
|
36 |
+
margin: 20px 0 !important;
|
37 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
|
38 |
+
}
|
39 |
+
|
40 |
+
.resposta-container pre code {
|
41 |
+
color: #1a1a1a !important;
|
42 |
+
background-color: #f8f9fa !important;
|
43 |
+
}
|
44 |
+
|
45 |
+
.pergunta-container {
|
46 |
+
background-color: #f0f8ff !important;
|
47 |
+
border-radius: 8px !important;
|
48 |
+
padding: 15px !important;
|
49 |
+
}
|
50 |
+
|
51 |
+
.titulo-principal {
|
52 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
53 |
+
color: white !important;
|
54 |
+
padding: 10px !important;
|
55 |
+
border-radius: 10px !important;
|
56 |
+
margin-bottom: 10px !important;
|
57 |
+
text-align: center !important;
|
58 |
+
}
|
59 |
+
|
60 |
+
.modelo-dropdown {
|
61 |
+
margin-bottom: 10px !important;
|
62 |
+
}
|
63 |
+
|
64 |
#entrada_usuario textarea {
|
65 |
+
color: white !important;
|
66 |
+
font-size: x-large !important;
|
67 |
+
background-color: #1a1a1a !important;
|
68 |
+
}
|
69 |
+
|
70 |
+
.message-content {
|
71 |
+
font-size: larger;
|
72 |
+
color: white !important;
|
73 |
+
background-color: #1a1a1a !important;
|
74 |
}
|
|
|
75 |
"""
|
76 |
|
77 |
def criar_interface():
|
78 |
with gr.Blocks(title="Dr. Aldo Henrique - API Externa", theme=gr.themes.Soft(), css=css_customizado) as interface:
|
79 |
+
with gr.Column(elem_classes="conteudo-principal"):
|
80 |
+
gr.HTML("""
|
81 |
+
<div class="titulo-principal">
|
82 |
+
<h1>🤖 iAldo - Pergunte e aprenda</h1>
|
83 |
+
<p style="font-size: 14px; opacity: 0.9;">Converse com o <a href="https://aldohenrique.com.br/" style="color: white; text-decoration: underline;">Prof. Dr. Aldo Henrique</a></p>
|
84 |
+
</div>
|
85 |
+
""")
|
|
|
86 |
|
87 |
+
chatbot = gr.Chatbot(label="💬 Chat com Dr. Aldo", elem_id="chat", scale=1)
|
88 |
|
|
|
89 |
modelo_select = gr.Dropdown(
|
90 |
choices=list(MODELS.keys()),
|
91 |
value=DEFAULT_MODEL,
|
|
|
94 |
elem_classes="modelo-dropdown"
|
95 |
)
|
96 |
|
97 |
+
with gr.Row():
|
98 |
+
user_input = gr.Textbox(
|
99 |
+
show_label=False,
|
100 |
+
placeholder="Digite sua pergunta e pressione Enter ou clique em Enviar",
|
101 |
+
lines=4,
|
102 |
+
elem_id="entrada_usuario"
|
103 |
+
)
|
104 |
+
enviar_btn = gr.Button("Enviar", variant="primary")
|
105 |
|
106 |
+
# Função de resposta
|
107 |
def responder(chat_history, user_msg, modelo):
|
108 |
if not user_msg.strip():
|
109 |
return chat_history, ""
|
|
|
|
|
110 |
chat_history = chat_history + [[user_msg, "Dr. Aldo Henrique está digitando..."]]
|
111 |
yield chat_history, ""
|
|
|
|
|
112 |
resposta_final = responder_como_aldo(user_msg, modelo)
|
|
|
|
|
113 |
chat_history[-1][1] = resposta_final
|
114 |
yield chat_history, ""
|
115 |
|
116 |
+
# Eventos de envio
|
117 |
enviar_btn.click(
|
118 |
fn=responder,
|
119 |
inputs=[chatbot, user_input, modelo_select],
|
120 |
outputs=[chatbot, user_input],
|
121 |
show_progress=True
|
122 |
)
|
|
|
123 |
user_input.submit(
|
124 |
fn=responder,
|
125 |
inputs=[chatbot, user_input, modelo_select],
|
|
|
161 |
### Sobre o Dr. Aldo Henrique:
|
162 |
- **Especialidade**: Linguagens C, Java, Desenvolvimento Web, Inteligência Artificial
|
163 |
- **Conhecimento Adicional**: Conteúdo do blog aldohenrique.com.br
|
|
|
|
|
|
|
|
|
164 |
""")
|
|
|
165 |
|
166 |
# Foco automático no campo de texto ao abrir
|
167 |
gr.HTML("""
|
|
|
173 |
}
|
174 |
});
|
175 |
</script>
|
176 |
+
""")
|
177 |
|
178 |
return interface
|
179 |
|