Update app.py
Browse files
app.py
CHANGED
@@ -12,18 +12,14 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
12 |
|
13 |
token=os.getenv('token')
|
14 |
print('token = ',token)
|
15 |
-
model_id = "CohereForAI/c4ai-command-r-plus-4bit"
|
16 |
|
17 |
-
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
18 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
19 |
|
20 |
-
bnb_config = BitsAndBytesConfig(load_in_8bit=True)
|
21 |
-
# messages = [{"role": "system", "content": system_message}]
|
22 |
|
23 |
-
|
24 |
tokenizer = AutoTokenizer.from_pretrained(model_id, token= token)
|
25 |
model = AutoModelForCausalLM.from_pretrained(model_id, token= token)
|
26 |
|
|
|
|
|
27 |
@spaces.GPU(duration=180)
|
28 |
def respond(
|
29 |
message,
|
@@ -34,21 +30,16 @@ def respond(
|
|
34 |
top_p,
|
35 |
):
|
36 |
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
# Format message with the command-r-plus chat template
|
41 |
-
|
42 |
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
43 |
-
|
44 |
-
|
45 |
gen_tokens = model.generate(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
gen_text = tokenizer.decode(gen_tokens[0])
|
53 |
print(gen_text)
|
54 |
yield gen_text
|
|
|
12 |
|
13 |
token=os.getenv('token')
|
14 |
print('token = ',token)
|
|
|
15 |
|
|
|
|
|
16 |
|
|
|
|
|
17 |
|
|
|
18 |
tokenizer = AutoTokenizer.from_pretrained(model_id, token= token)
|
19 |
model = AutoModelForCausalLM.from_pretrained(model_id, token= token)
|
20 |
|
21 |
+
|
22 |
+
|
23 |
@spaces.GPU(duration=180)
|
24 |
def respond(
|
25 |
message,
|
|
|
30 |
top_p,
|
31 |
):
|
32 |
messages = [{"role": "user", "content": "Hello, how are you?"}]
|
|
|
|
|
|
|
|
|
|
|
33 |
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
34 |
+
## <BOS_TOKEN><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hello, how are you?<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>
|
35 |
+
|
36 |
gen_tokens = model.generate(
|
37 |
+
input_ids,
|
38 |
+
max_new_tokens=100,
|
39 |
+
do_sample=True,
|
40 |
+
temperature=0.3,
|
41 |
+
)
|
42 |
+
|
43 |
gen_text = tokenizer.decode(gen_tokens[0])
|
44 |
print(gen_text)
|
45 |
yield gen_text
|