Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,10 +46,20 @@ with gr.Blocks() as demo:
|
|
| 46 |
chatbot = gr.Chatbot()
|
| 47 |
entrada = gr.Textbox(placeholder="Digite sua pergunta…", show_label=False)
|
| 48 |
|
| 49 |
-
def interagir(msg):
|
|
|
|
|
|
|
| 50 |
resposta = responder(msg)
|
| 51 |
-
return "", chatbot.append((msg, resposta))
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
demo.launch()
|
|
|
|
| 46 |
chatbot = gr.Chatbot()
|
| 47 |
entrada = gr.Textbox(placeholder="Digite sua pergunta…", show_label=False)
|
| 48 |
|
| 49 |
+
def interagir(msg, history): # Adicione 'history' como entrada para obter o histórico atual
|
| 50 |
+
# 'history' é o estado atual do chatbot, uma lista de [pergunta, resposta]
|
| 51 |
+
# Primeiro, obtenha a resposta da sua cadeia de chat
|
| 52 |
resposta = responder(msg)
|
|
|
|
| 53 |
|
| 54 |
+
# Adicione a nova pergunta e resposta ao histórico
|
| 55 |
+
history.append([msg, resposta])
|
| 56 |
+
|
| 57 |
+
# Retorne uma tupla:
|
| 58 |
+
# 1. Uma string vazia para limpar a caixa de entrada (entrada)
|
| 59 |
+
# 2. O histórico atualizado para o chatbot
|
| 60 |
+
return "", history # Retorna a lista de mensagens para o chatbot
|
| 61 |
+
|
| 62 |
+
# Adapte o submit para passar o histórico do chatbot como entrada
|
| 63 |
+
entrada.submit(interagir, [entrada, chatbot], [entrada, chatbot])
|
| 64 |
|
| 65 |
demo.launch()
|