aldohenrique commited on
Commit
bdf9792
·
verified ·
1 Parent(s): 83879af

Update interface.py

Browse files
Files changed (1) hide show
  1. interface.py +11 -6
interface.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from ai_logic import (
3
  responder_como_aldo,
4
  build_and_save_vector_store,
@@ -119,6 +120,8 @@ css_customizado = """
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">
@@ -129,7 +132,7 @@ def criar_interface():
129
  with gr.Column(elem_classes="chat-area"):
130
  with gr.Column(elem_classes="chat-container"):
131
  chatbot = gr.Chatbot(
132
- label="💬 Area do chat",
133
  elem_id="chat",
134
  height="100%"
135
  )
@@ -182,27 +185,29 @@ def criar_interface():
182
  - Peça resumos ou opiniões sobre temas que o professor aborda.
183
  """)
184
 
185
- def responder(chat_history, user_msg, modelo):
 
186
  if not user_msg.strip():
187
  return chat_history, ""
188
 
189
  chat_history = chat_history + [[user_msg, "Dr. Aldo Henrique está digitando..."]]
190
  yield chat_history, ""
191
 
192
- resposta_final = responder_como_aldo(user_msg, modelo)
193
  chat_history[-1][1] = resposta_final
194
  yield chat_history, ""
195
 
 
196
  enviar_btn.click(
197
  fn=responder,
198
- inputs=[chatbot, user_input, modelo_select],
199
  outputs=[chatbot, user_input],
200
  show_progress=True
201
  )
202
 
203
  user_input.submit(
204
  fn=responder,
205
- inputs=[chatbot, user_input, modelo_select],
206
  outputs=[chatbot, user_input],
207
  show_progress=True
208
  )
@@ -227,4 +232,4 @@ def criar_interface():
227
  return interface
228
 
229
  def configurar_interface():
230
- return criar_interface()
 
1
  import gradio as gr
2
+ import uuid
3
  from ai_logic import (
4
  responder_como_aldo,
5
  build_and_save_vector_store,
 
120
 
121
  def criar_interface():
122
  with gr.Blocks(title="Dr. Aldo Henrique - API Externa", theme=gr.themes.Soft(), css=css_customizado) as interface:
123
+ session_id_state = gr.State(str(uuid.uuid4())) # Geração do session_id único
124
+
125
  with gr.Column(elem_classes="main-content"):
126
  gr.HTML("""
127
  <div class="titulo-principal">
 
132
  with gr.Column(elem_classes="chat-area"):
133
  with gr.Column(elem_classes="chat-container"):
134
  chatbot = gr.Chatbot(
135
+ label="💬 Área do chat",
136
  elem_id="chat",
137
  height="100%"
138
  )
 
185
  - Peça resumos ou opiniões sobre temas que o professor aborda.
186
  """)
187
 
188
+ # Função corrigida com uso de session_id
189
+ def responder(chat_history, user_msg, modelo, session_id):
190
  if not user_msg.strip():
191
  return chat_history, ""
192
 
193
  chat_history = chat_history + [[user_msg, "Dr. Aldo Henrique está digitando..."]]
194
  yield chat_history, ""
195
 
196
+ resposta_final = responder_como_aldo(session_id, user_msg, modelo)
197
  chat_history[-1][1] = resposta_final
198
  yield chat_history, ""
199
 
200
+ # ✅ Botão e Enter usam o novo estado de sessão
201
  enviar_btn.click(
202
  fn=responder,
203
+ inputs=[chatbot, user_input, modelo_select, session_id_state],
204
  outputs=[chatbot, user_input],
205
  show_progress=True
206
  )
207
 
208
  user_input.submit(
209
  fn=responder,
210
+ inputs=[chatbot, user_input, modelo_select, session_id_state],
211
  outputs=[chatbot, user_input],
212
  show_progress=True
213
  )
 
232
  return interface
233
 
234
  def configurar_interface():
235
+ return criar_interface()