Spaces:
Running
Running
Update interface.py
Browse files- interface.py +86 -127
interface.py
CHANGED
@@ -8,147 +8,118 @@ from ai_logic import (
|
|
8 |
)
|
9 |
|
10 |
css_customizado = """
|
11 |
-
.gradio-container {
|
12 |
-
max-width: 1400px !important;
|
13 |
-
margin: 0 auto;
|
14 |
-
width:
|
15 |
height: 100vh !important;
|
16 |
-
display: flex;
|
17 |
-
flex-direction: column;
|
18 |
overflow: hidden;
|
19 |
}
|
20 |
|
21 |
.main-content {
|
22 |
display: flex;
|
23 |
flex-direction: column;
|
24 |
-
|
25 |
overflow: hidden;
|
|
|
26 |
}
|
27 |
|
28 |
-
.titulo-principal {
|
29 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
30 |
-
color: white !important;
|
31 |
padding: 20px !important;
|
32 |
-
border-radius: 10px !important;
|
33 |
-
margin: 10px !important;
|
34 |
-
text-align: center !important;
|
35 |
flex-shrink: 0;
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
.chat-container {
|
39 |
-
flex
|
40 |
overflow-y: auto;
|
41 |
-
margin: 10px
|
42 |
-
min-height: 40vh !important;
|
43 |
}
|
44 |
|
45 |
.input-container {
|
46 |
flex-shrink: 0;
|
47 |
-
padding: 10px
|
48 |
display: flex;
|
49 |
flex-direction: column;
|
50 |
-
|
51 |
}
|
52 |
|
53 |
.additional-content {
|
54 |
overflow-y: auto;
|
55 |
-
padding:
|
56 |
-
flex-shrink: 0;
|
57 |
-
}
|
58 |
-
|
59 |
-
.gr-textbox textarea {
|
60 |
-
font-size: 14px !important;
|
61 |
-
line-height: 1.5 !important;
|
62 |
}
|
63 |
|
64 |
-
.
|
65 |
-
|
66 |
-
|
67 |
-
border: 1px solid #e0e0e0 !important;
|
68 |
-
border-radius: 20px !important;
|
69 |
-
padding: 20px !important;
|
70 |
-
margin: 10px 0 !important;
|
71 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
|
72 |
}
|
73 |
|
74 |
-
.resposta-container
|
75 |
-
color: #
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
padding: 15px !important;
|
83 |
}
|
84 |
|
85 |
-
.
|
86 |
-
|
|
|
87 |
}
|
88 |
|
89 |
-
.
|
90 |
-
|
|
|
|
|
91 |
}
|
92 |
|
93 |
-
|
94 |
-
|
95 |
}
|
96 |
|
97 |
#entrada_usuario textarea {
|
98 |
-
color: white !important;
|
99 |
-
font-size: large !important;
|
100 |
-
background-color: #1a1a1a !important;
|
101 |
min-height: 60px !important;
|
102 |
}
|
103 |
|
104 |
-
.message-content {
|
105 |
-
font-size: larger;
|
106 |
-
color: white !important;
|
107 |
-
background-color: #1a1a1a !important;
|
108 |
}
|
109 |
|
110 |
-
/* Responsivo
|
111 |
@media (max-width: 768px) {
|
112 |
.titulo-principal {
|
113 |
padding: 15px !important;
|
114 |
-
margin: 5px !important;
|
115 |
}
|
116 |
-
|
117 |
-
.chat-container {
|
118 |
-
min-height: 35vh !important;
|
119 |
-
}
|
120 |
-
|
121 |
-
.input-container {
|
122 |
-
padding: 5px !important;
|
123 |
-
}
|
124 |
-
|
125 |
#entrada_usuario textarea {
|
126 |
min-height: 50px !important;
|
127 |
font-size: 16px !important;
|
128 |
}
|
129 |
}
|
130 |
-
|
131 |
-
@media (max-width: 480px) {
|
132 |
-
.titulo-principal {
|
133 |
-
padding: 10px !important;
|
134 |
-
margin: 5px !important;
|
135 |
-
}
|
136 |
-
|
137 |
-
.chat-container {
|
138 |
-
min-height: 30vh !important;
|
139 |
-
}
|
140 |
-
|
141 |
-
.input-container {
|
142 |
-
padding: 5px !important;
|
143 |
-
}
|
144 |
-
}
|
145 |
"""
|
146 |
|
147 |
def criar_interface():
|
148 |
with gr.Blocks(title="Dr. Aldo Henrique - API Externa", theme=gr.themes.Soft(), css=css_customizado) as interface:
|
149 |
-
# Contêiner principal para o conteúdo visível
|
150 |
with gr.Column(elem_classes="main-content"):
|
151 |
-
# Cabeçalho
|
152 |
gr.HTML("""
|
153 |
<div class="titulo-principal">
|
154 |
<h4>🤖 iAldo - Pergunte e aprenda</h4>
|
@@ -156,44 +127,39 @@ def criar_interface():
|
|
156 |
</div>
|
157 |
""")
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
)
|
166 |
-
|
167 |
-
# Área de entrada
|
168 |
-
with gr.Column(elem_classes="input-container"):
|
169 |
-
with gr.Row():
|
170 |
-
modelo_select = gr.Dropdown(
|
171 |
-
choices=list(MODELS.keys()),
|
172 |
-
value=DEFAULT_MODEL,
|
173 |
-
label="🧠 Selecione o Modelo de IA",
|
174 |
-
info="Escolha o modelo para responder",
|
175 |
-
elem_classes="modelo-dropdown"
|
176 |
)
|
177 |
|
178 |
-
with gr.
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
-
# Conteúdo adicional (fora da visualização inicial)
|
188 |
with gr.Column(elem_classes="additional-content"):
|
189 |
-
# RAG
|
190 |
with gr.Accordion("⚙️ Controle do Conhecimento (RAG)", open=False):
|
191 |
status_rag = gr.Textbox(label="Status do Retreino", interactive=False)
|
192 |
botao_retreinar = gr.Button("🔄 Atualizar Conhecimento do Blog", variant="stop")
|
193 |
download_faiss_file = gr.File(label="Download do Índice FAISS", interactive=False, file_count="single", file_types=[".pkl"])
|
194 |
download_urls_file = gr.File(label="Download das URLs Processadas", interactive=False, file_count="single", file_types=[".pkl"])
|
195 |
|
196 |
-
# Exemplos
|
197 |
with gr.Accordion("📚 Exemplos de Perguntas", open=False):
|
198 |
gr.Examples(
|
199 |
examples=[
|
@@ -204,11 +170,9 @@ def criar_interface():
|
|
204 |
inputs=[user_input, modelo_select]
|
205 |
)
|
206 |
|
207 |
-
# Status API
|
208 |
with gr.Accordion("🔧 Status da API", open=False):
|
209 |
status_api = gr.Textbox(label="Status dos Modelos", interactive=False, lines=8)
|
210 |
|
211 |
-
# Informações
|
212 |
with gr.Accordion("ℹ️ Informações", open=False):
|
213 |
gr.Markdown("""
|
214 |
### Sobre o Dr. Aldo Henrique:
|
@@ -223,15 +187,11 @@ def criar_interface():
|
|
223 |
def responder(chat_history, user_msg, modelo):
|
224 |
if not user_msg.strip():
|
225 |
return chat_history, ""
|
226 |
-
|
227 |
-
# Adiciona a mensagem do usuário e uma resposta temporária
|
228 |
chat_history = chat_history + [[user_msg, "Dr. Aldo Henrique está digitando..."]]
|
229 |
yield chat_history, ""
|
230 |
-
|
231 |
-
# Gera a resposta real
|
232 |
resposta_final = responder_como_aldo(user_msg, modelo)
|
233 |
-
|
234 |
-
# Atualiza com a resposta final
|
235 |
chat_history[-1][1] = resposta_final
|
236 |
yield chat_history, ""
|
237 |
|
@@ -255,19 +215,18 @@ def criar_interface():
|
|
255 |
show_progress=True
|
256 |
)
|
257 |
|
258 |
-
# Foco automático no campo de texto ao abrir
|
259 |
gr.HTML("""
|
260 |
<script>
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
</script>
|
268 |
""")
|
269 |
|
270 |
return interface
|
271 |
|
272 |
def configurar_interface():
|
273 |
-
return criar_interface()
|
|
|
8 |
)
|
9 |
|
10 |
css_customizado = """
|
11 |
+
.gradio-container {
|
12 |
+
max-width: 1400px !important;
|
13 |
+
margin: 0 auto;
|
14 |
+
width: 99%;
|
15 |
height: 100vh !important;
|
16 |
+
display: flex;
|
17 |
+
flex-direction: column;
|
18 |
overflow: hidden;
|
19 |
}
|
20 |
|
21 |
.main-content {
|
22 |
display: flex;
|
23 |
flex-direction: column;
|
24 |
+
height: 100vh;
|
25 |
overflow: hidden;
|
26 |
+
flex-shrink: 0;
|
27 |
}
|
28 |
|
29 |
+
.titulo-principal {
|
30 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
31 |
+
color: white !important;
|
32 |
padding: 20px !important;
|
33 |
+
border-radius: 10px !important;
|
34 |
+
margin-bottom: 10px !important;
|
35 |
+
text-align: center !important;
|
36 |
flex-shrink: 0;
|
37 |
}
|
38 |
|
39 |
+
.chat-area {
|
40 |
+
flex: 1;
|
41 |
+
display: flex;
|
42 |
+
flex-direction: column;
|
43 |
+
overflow: hidden;
|
44 |
+
}
|
45 |
+
|
46 |
.chat-container {
|
47 |
+
flex: 1;
|
48 |
overflow-y: auto;
|
49 |
+
margin-bottom: 10px;
|
|
|
50 |
}
|
51 |
|
52 |
.input-container {
|
53 |
flex-shrink: 0;
|
54 |
+
padding: 10px 0;
|
55 |
display: flex;
|
56 |
flex-direction: column;
|
57 |
+
justify-content: center;
|
58 |
}
|
59 |
|
60 |
.additional-content {
|
61 |
overflow-y: auto;
|
62 |
+
padding-top: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
|
65 |
+
.gr-textbox textarea {
|
66 |
+
font-size: 14px !important;
|
67 |
+
line-height: 1.5 !important;
|
|
|
|
|
|
|
|
|
|
|
68 |
}
|
69 |
|
70 |
+
.resposta-container {
|
71 |
+
background-color: #ffffff !important;
|
72 |
+
color: #1a1a1a !important;
|
73 |
+
border: 1px solid #e0e0e0 !important;
|
74 |
+
border-radius: 20px !important;
|
75 |
+
padding: 20px !important;
|
76 |
+
margin: 10px 0 !important;
|
77 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
|
|
|
78 |
}
|
79 |
|
80 |
+
.resposta-container pre code {
|
81 |
+
color: #1a1a1a !important;
|
82 |
+
background-color: #f8f9fa !important;
|
83 |
}
|
84 |
|
85 |
+
.pergunta-container {
|
86 |
+
background-color: #f0f8ff !important;
|
87 |
+
border-radius: 8px !important;
|
88 |
+
padding: 15px !important;
|
89 |
}
|
90 |
|
91 |
+
.modelo-dropdown {
|
92 |
+
margin-bottom: 15px !important;
|
93 |
}
|
94 |
|
95 |
#entrada_usuario textarea {
|
96 |
+
color: white !important;
|
97 |
+
font-size: large !important;
|
98 |
+
background-color: #1a1a1a !important;
|
99 |
min-height: 60px !important;
|
100 |
}
|
101 |
|
102 |
+
.message-content {
|
103 |
+
font-size: larger;
|
104 |
+
color: white !important;
|
105 |
+
background-color: #1a1a1a !important;
|
106 |
}
|
107 |
|
108 |
+
/* Responsivo */
|
109 |
@media (max-width: 768px) {
|
110 |
.titulo-principal {
|
111 |
padding: 15px !important;
|
|
|
112 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
#entrada_usuario textarea {
|
114 |
min-height: 50px !important;
|
115 |
font-size: 16px !important;
|
116 |
}
|
117 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
"""
|
119 |
|
120 |
def criar_interface():
|
121 |
with gr.Blocks(title="Dr. Aldo Henrique - API Externa", theme=gr.themes.Soft(), css=css_customizado) as interface:
|
|
|
122 |
with gr.Column(elem_classes="main-content"):
|
|
|
123 |
gr.HTML("""
|
124 |
<div class="titulo-principal">
|
125 |
<h4>🤖 iAldo - Pergunte e aprenda</h4>
|
|
|
127 |
</div>
|
128 |
""")
|
129 |
|
130 |
+
with gr.Column(elem_classes="chat-area"):
|
131 |
+
with gr.Column(elem_classes="chat-container"):
|
132 |
+
chatbot = gr.Chatbot(
|
133 |
+
label="💬 Chat com Dr. Aldo",
|
134 |
+
elem_id="chat",
|
135 |
+
height="100%"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
)
|
137 |
|
138 |
+
with gr.Column(elem_classes="input-container"):
|
139 |
+
with gr.Row():
|
140 |
+
modelo_select = gr.Dropdown(
|
141 |
+
choices=list(MODELS.keys()),
|
142 |
+
value=DEFAULT_MODEL,
|
143 |
+
label="🧠 Selecione o Modelo de IA",
|
144 |
+
info="Escolha o modelo para responder",
|
145 |
+
elem_classes="modelo-dropdown"
|
146 |
+
)
|
147 |
+
with gr.Row():
|
148 |
+
user_input = gr.Textbox(
|
149 |
+
show_label=False,
|
150 |
+
placeholder="Digite sua pergunta e pressione Enter ou clique em Enviar",
|
151 |
+
lines=2,
|
152 |
+
elem_id="entrada_usuario"
|
153 |
+
)
|
154 |
+
enviar_btn = gr.Button("Enviar", variant="primary")
|
155 |
|
|
|
156 |
with gr.Column(elem_classes="additional-content"):
|
|
|
157 |
with gr.Accordion("⚙️ Controle do Conhecimento (RAG)", open=False):
|
158 |
status_rag = gr.Textbox(label="Status do Retreino", interactive=False)
|
159 |
botao_retreinar = gr.Button("🔄 Atualizar Conhecimento do Blog", variant="stop")
|
160 |
download_faiss_file = gr.File(label="Download do Índice FAISS", interactive=False, file_count="single", file_types=[".pkl"])
|
161 |
download_urls_file = gr.File(label="Download das URLs Processadas", interactive=False, file_count="single", file_types=[".pkl"])
|
162 |
|
|
|
163 |
with gr.Accordion("📚 Exemplos de Perguntas", open=False):
|
164 |
gr.Examples(
|
165 |
examples=[
|
|
|
170 |
inputs=[user_input, modelo_select]
|
171 |
)
|
172 |
|
|
|
173 |
with gr.Accordion("🔧 Status da API", open=False):
|
174 |
status_api = gr.Textbox(label="Status dos Modelos", interactive=False, lines=8)
|
175 |
|
|
|
176 |
with gr.Accordion("ℹ️ Informações", open=False):
|
177 |
gr.Markdown("""
|
178 |
### Sobre o Dr. Aldo Henrique:
|
|
|
187 |
def responder(chat_history, user_msg, modelo):
|
188 |
if not user_msg.strip():
|
189 |
return chat_history, ""
|
190 |
+
|
|
|
191 |
chat_history = chat_history + [[user_msg, "Dr. Aldo Henrique está digitando..."]]
|
192 |
yield chat_history, ""
|
193 |
+
|
|
|
194 |
resposta_final = responder_como_aldo(user_msg, modelo)
|
|
|
|
|
195 |
chat_history[-1][1] = resposta_final
|
196 |
yield chat_history, ""
|
197 |
|
|
|
215 |
show_progress=True
|
216 |
)
|
217 |
|
|
|
218 |
gr.HTML("""
|
219 |
<script>
|
220 |
+
window.addEventListener("load", function() {
|
221 |
+
const textarea = document.querySelector("#entrada_usuario textarea");
|
222 |
+
if (textarea) {
|
223 |
+
setTimeout(() => textarea.focus(), 100);
|
224 |
+
}
|
225 |
+
});
|
226 |
</script>
|
227 |
""")
|
228 |
|
229 |
return interface
|
230 |
|
231 |
def configurar_interface():
|
232 |
+
return criar_interface()
|