Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,15 +41,21 @@ if __name__ == '__main__':
|
|
41 |
)
|
42 |
logger.info(f"chatpdf model: {model}")
|
43 |
|
44 |
-
|
45 |
-
def predict(message, history):
|
46 |
history_format = []
|
47 |
for human, assistant in history:
|
48 |
history_format.append([human, assistant])
|
49 |
model.history = history_format
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
response, reference_results = model.predict(message)
|
51 |
r = response + "\n\n" + '\n'.join(reference_results)
|
52 |
-
|
|
|
53 |
|
54 |
# Crear el chatbot
|
55 |
chatbot_stream = gr.Chatbot(
|
@@ -66,11 +72,12 @@ if __name__ == '__main__':
|
|
66 |
examples = ['Puede hablarme del PNL?', 'Introducci贸n a la PNL']
|
67 |
|
68 |
# Crear la interfaz sin utilizar la funci贸n que usa yield
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
outputs=[chatbot_stream, gr.State()],
|
73 |
title=title,
|
|
|
|
|
74 |
css=css,
|
75 |
examples=examples,
|
76 |
theme='soft',
|
|
|
41 |
)
|
42 |
logger.info(f"chatpdf model: {model}")
|
43 |
|
44 |
+
def predict_stream(message, history):
|
|
|
45 |
history_format = []
|
46 |
for human, assistant in history:
|
47 |
history_format.append([human, assistant])
|
48 |
model.history = history_format
|
49 |
+
for chunk in model.predict_stream(message):
|
50 |
+
yield chunk
|
51 |
+
|
52 |
+
|
53 |
+
def predict(message, history):
|
54 |
+
logger.debug(message)
|
55 |
response, reference_results = model.predict(message)
|
56 |
r = response + "\n\n" + '\n'.join(reference_results)
|
57 |
+
logger.debug(r)
|
58 |
+
return r
|
59 |
|
60 |
# Crear el chatbot
|
61 |
chatbot_stream = gr.Chatbot(
|
|
|
72 |
examples = ['Puede hablarme del PNL?', 'Introducci贸n a la PNL']
|
73 |
|
74 |
# Crear la interfaz sin utilizar la funci贸n que usa yield
|
75 |
+
chat_interface_stream = gr.ChatInterface(
|
76 |
+
predict_stream,
|
77 |
+
textbox=gr.Textbox(lines=4, placeholder="Ask me question", scale=7), # A帽adir submit=True
|
|
|
78 |
title=title,
|
79 |
+
# description=description,
|
80 |
+
chatbot=chatbot_stream,
|
81 |
css=css,
|
82 |
examples=examples,
|
83 |
theme='soft',
|