Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import torch
|
|
8 |
from transformers import AutoModelForCausalLM, GemmaTokenizerFast, TextIteratorStreamer
|
9 |
|
10 |
DESCRIPTION = """\
|
11 |
-
# Monlam LLM
|
12 |
"""
|
13 |
|
14 |
MAX_MAX_NEW_TOKENS = 2048
|
@@ -16,8 +16,8 @@ DEFAULT_MAX_NEW_TOKENS = 1024
|
|
16 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
17 |
|
18 |
# Load the model and tokenizer
|
19 |
-
tokenizer = GemmaTokenizerFast.from_pretrained("
|
20 |
-
model = AutoModelForCausalLM.from_pretrained("
|
21 |
|
22 |
model.config.sliding_window = 4096
|
23 |
model.eval()
|
@@ -37,8 +37,20 @@ def generate(
|
|
37 |
# Clear the stop event before starting a new generation
|
38 |
stop_event.clear()
|
39 |
|
|
|
40 |
# Append the user's message to the conversation history
|
41 |
conversation = chat_history.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
conversation.append({"role": "user", "content": message})
|
43 |
|
44 |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt")
|
|
|
8 |
from transformers import AutoModelForCausalLM, GemmaTokenizerFast, TextIteratorStreamer
|
9 |
|
10 |
DESCRIPTION = """\
|
11 |
+
# Monlam LLM v2.0.1
|
12 |
"""
|
13 |
|
14 |
MAX_MAX_NEW_TOKENS = 2048
|
|
|
16 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
17 |
|
18 |
# Load the model and tokenizer
|
19 |
+
tokenizer = GemmaTokenizerFast.from_pretrained("example_v1.0.2")
|
20 |
+
model = AutoModelForCausalLM.from_pretrained("example_v1.0.2", torch_dtype=torch.float16).to("cuda")
|
21 |
|
22 |
model.config.sliding_window = 4096
|
23 |
model.eval()
|
|
|
37 |
# Clear the stop event before starting a new generation
|
38 |
stop_event.clear()
|
39 |
|
40 |
+
|
41 |
# Append the user's message to the conversation history
|
42 |
conversation = chat_history.copy()
|
43 |
+
if not conversation:
|
44 |
+
conversation.extend([
|
45 |
+
{
|
46 |
+
"role": "user",
|
47 |
+
"content": "ཁྱེད་རང་སྨོན་ལམ་མི་བཟོས་རིག་ནུས་ཤིག་ཡིན་པ་དང་ཁྱེད་རང་མི་བཟོས་རིག་ནུས་(AI)ཤིག་ཡིན།"
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"role": "assistant",
|
51 |
+
"content": "ལགས་སོ། ང་ཡིས་ཁྱེད་ཀྱི་བཀའ་བཞིན་སྒྲུབ་ཆོག"
|
52 |
+
}
|
53 |
+
])
|
54 |
conversation.append({"role": "user", "content": message})
|
55 |
|
56 |
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt")
|