Update app.py
Browse files
app.py
CHANGED
@@ -12,18 +12,25 @@ def correct_words(text):
|
|
12 |
corrected_words = [spell.correction(word) for word in words]
|
13 |
corrected_text = ' '.join(corrected_words)
|
14 |
return corrected_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def generate_response(message):
|
17 |
global history
|
18 |
-
for _ in range(2):
|
19 |
-
tokens = [ord(char) for char in message]
|
20 |
-
response = llm.
|
21 |
-
response_text = ' '.join(map(str, response))
|
22 |
time.sleep(2)
|
23 |
corrected_response = correct_words(response_text)
|
24 |
history.append(corrected_response)
|
25 |
yield ' '.join(history)
|
26 |
-
|
27 |
history = ["Chatbot:"]
|
28 |
# Clear the history list after the last response
|
29 |
history = ["Chatbot:"]
|
|
|
12 |
corrected_words = [spell.correction(word) for word in words]
|
13 |
corrected_text = ' '.join(corrected_words)
|
14 |
return corrected_text
|
15 |
+
import asyncio
|
16 |
+
|
17 |
+
# ... (previous code)
|
18 |
+
|
19 |
+
async def generate_async(tokens):
|
20 |
+
for token in tokens:
|
21 |
+
yield token
|
22 |
|
23 |
def generate_response(message):
|
24 |
global history
|
25 |
+
for _ in range(2):
|
26 |
+
tokens = [ord(char) for char in message]
|
27 |
+
response = llm.generate_async(tokens=tokens, top_k=50, top_p=0.95, temperature=1.0, repetition_penalty=1.0, last_n_tokens=1)
|
28 |
+
response_text = ' '.join(map(str, await asyncio.gather(*response)))
|
29 |
time.sleep(2)
|
30 |
corrected_response = correct_words(response_text)
|
31 |
history.append(corrected_response)
|
32 |
yield ' '.join(history)
|
33 |
+
history = ["Chatbot:"]
|
34 |
history = ["Chatbot:"]
|
35 |
# Clear the history list after the last response
|
36 |
history = ["Chatbot:"]
|