Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,34 @@ from threading import Thread
|
|
| 6 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 7 |
|
| 8 |
|
| 9 |
-
TITLE = "Chat with Llama3-8B-Chinese"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
DESCRIPTION = "Visit <a href='https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat' target='_blank'>our model page</a> for details."
|
| 12 |
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat")
|
| 14 |
model = AutoModelForCausalLM.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat", device_map="auto")
|
|
@@ -40,7 +65,7 @@ def stream_chat(message: str, history: list, system: str, temperature: float, ma
|
|
| 40 |
|
| 41 |
output = ""
|
| 42 |
for new_token in streamer:
|
| 43 |
-
|
| 44 |
yield output
|
| 45 |
|
| 46 |
|
|
@@ -73,8 +98,10 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 73 |
),
|
| 74 |
],
|
| 75 |
examples=[
|
| 76 |
-
["我的蓝牙耳机坏了,我该去看牙科还是耳鼻喉科?"],
|
| 77 |
-
["
|
|
|
|
|
|
|
| 78 |
],
|
| 79 |
cache_examples=False,
|
| 80 |
title=TITLE,
|
|
|
|
| 6 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
| 7 |
|
| 8 |
|
| 9 |
+
TITLE = "<center>Chat with Llama3-8B-Chinese</center>"
|
| 10 |
+
|
| 11 |
+
DESCRIPTION = "<h3><center>Visit <a href='https://huggingface.co/shenzhi-wang/Llama3-8B-Chinese-Chat' target='_blank'>our model page</a> for details.</center></h3>"
|
| 12 |
+
|
| 13 |
+
TOOL_EXAMPLE = '''You have access to the following tools:
|
| 14 |
+
```python
|
| 15 |
+
def google_search(keywords: List[str]):
|
| 16 |
+
"""
|
| 17 |
+
Search on the Internet based on the keywords.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
keywords (List[str]): Keywords for the search engine.
|
| 21 |
+
"""
|
| 22 |
+
pass
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
Write "Action:" followed by a list of actions in JSON that you want to call, e.g.
|
| 26 |
+
Action:
|
| 27 |
+
```json
|
| 28 |
+
[
|
| 29 |
+
{
|
| 30 |
+
"name": "tool name (one of [google_search])",
|
| 31 |
+
"arguments": "the input to the tool"
|
| 32 |
+
}
|
| 33 |
+
]
|
| 34 |
+
```
|
| 35 |
+
'''
|
| 36 |
|
|
|
|
| 37 |
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat")
|
| 39 |
model = AutoModelForCausalLM.from_pretrained("shenzhi-wang/Llama3-8B-Chinese-Chat", device_map="auto")
|
|
|
|
| 65 |
|
| 66 |
output = ""
|
| 67 |
for new_token in streamer:
|
| 68 |
+
output += new_token
|
| 69 |
yield output
|
| 70 |
|
| 71 |
|
|
|
|
| 98 |
),
|
| 99 |
],
|
| 100 |
examples=[
|
| 101 |
+
["我的蓝牙耳机坏了,我该去看牙科还是耳鼻喉科?", "You are a helpful assistant."],
|
| 102 |
+
["在一道没有余数的除法算式里,被除数(不为零)加上除数和商的积,再除以被除数,所得的商是多少?", "You are a helpful assistant."],
|
| 103 |
+
["今日行军进展如何?", "扮演诸葛亮和我对话。"],
|
| 104 |
+
["羊驼的寿命有多久?", TOOL_EXAMPLE],
|
| 105 |
],
|
| 106 |
cache_examples=False,
|
| 107 |
title=TITLE,
|