Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
def respond(
|
11 |
message,
|
12 |
history: list[tuple[str, str]],
|
@@ -15,30 +20,22 @@ def respond(
|
|
15 |
temperature,
|
16 |
top_p,
|
17 |
):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
"""
|
43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
from gpt4all import GPT4All
|
4 |
"""
|
5 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
"""
|
7 |
+
model = GPT4All(model_name='strela-q4_k_m.gguf', model_path=os.getcwd())
|
8 |
+
|
9 |
+
def stop_on_token_callback(token_id, token_string):
|
10 |
+
print(token_string, end='')
|
11 |
+
if '#' in token_string:
|
12 |
+
return False
|
13 |
+
else:
|
14 |
+
return True
|
15 |
def respond(
|
16 |
message,
|
17 |
history: list[tuple[str, str]],
|
|
|
20 |
temperature,
|
21 |
top_p,
|
22 |
):
|
23 |
+
chat = f"""### System:
|
24 |
+
{system_message}
|
25 |
+
"""
|
26 |
+
for group in history:
|
27 |
+
chat += f"""### Human:
|
28 |
+
{group[0]}
|
29 |
+
### Assistant:
|
30 |
+
{group[1]}"""
|
31 |
+
chat += f"""### Human:
|
32 |
+
{message}
|
33 |
+
### Assistant:
|
34 |
+
"""
|
35 |
+
tokens = ""
|
36 |
+
for token in model.generate(chat, temp=temperature, callback=stop_on_token_callback, streaming=True):
|
37 |
+
tokens += token
|
38 |
+
yield tokens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
"""
|
40 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
41 |
"""
|