Spaces:
Runtime error
Runtime error
kingabzpro
commited on
Commit
•
9e61cec
1
Parent(s):
031bf13
Update app.py
Browse files
app.py
CHANGED
@@ -4,34 +4,50 @@ import torch
|
|
4 |
|
5 |
|
6 |
title = "🦅Falcon 🗨️ChatBot"
|
7 |
-
description ="Falcon-RW-1B is a 1B parameters causal decoder-only model built by TII and trained on 350B tokens of RefinedWeb."
|
8 |
examples = [["How are you?"]]
|
9 |
|
10 |
|
11 |
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-rw-1b")
|
12 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def predict(input, history=[]):
|
15 |
# tokenize the new input sentence
|
16 |
-
new_user_input_ids = tokenizer.encode(
|
|
|
|
|
17 |
|
18 |
# append the new user input tokens to the chat history
|
19 |
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
20 |
|
21 |
-
# generate a response
|
22 |
-
history = model.generate(
|
|
|
|
|
23 |
|
24 |
# convert the tokens to text, and then split the responses into lines
|
25 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
26 |
-
#print('decoded_response-->>'+str(response))
|
27 |
-
response = [
|
28 |
-
|
|
|
|
|
29 |
return response, history
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
title = "🦅Falcon 🗨️ChatBot"
|
7 |
+
description = "Falcon-RW-1B is a 1B parameters causal decoder-only model built by TII and trained on 350B tokens of RefinedWeb."
|
8 |
examples = [["How are you?"]]
|
9 |
|
10 |
|
11 |
tokenizer = AutoTokenizer.from_pretrained("tiiuae/falcon-rw-1b")
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(
|
13 |
+
"tiiuae/falcon-rw-1b",
|
14 |
+
trust_remote_code=True,
|
15 |
+
torch_dtype=torch.bfloat16,
|
16 |
+
trust_remote_code=True,
|
17 |
+
device_map="auto",
|
18 |
+
)
|
19 |
+
|
20 |
|
21 |
def predict(input, history=[]):
|
22 |
# tokenize the new input sentence
|
23 |
+
new_user_input_ids = tokenizer.encode(
|
24 |
+
input + tokenizer.eos_token, return_tensors="pt"
|
25 |
+
)
|
26 |
|
27 |
# append the new user input tokens to the chat history
|
28 |
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
29 |
|
30 |
+
# generate a response
|
31 |
+
history = model.generate(
|
32 |
+
bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id
|
33 |
+
).tolist()
|
34 |
|
35 |
# convert the tokens to text, and then split the responses into lines
|
36 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
37 |
+
# print('decoded_response-->>'+str(response))
|
38 |
+
response = [
|
39 |
+
(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)
|
40 |
+
] # convert to tuples of list
|
41 |
+
# print('response-->>'+str(response))
|
42 |
return response, history
|
43 |
|
44 |
+
|
45 |
+
gr.Interface(
|
46 |
+
fn=predict,
|
47 |
+
title=title,
|
48 |
+
description=description,
|
49 |
+
examples=examples,
|
50 |
+
inputs=["text", "state"],
|
51 |
+
outputs=["chatbot", "state"],
|
52 |
+
theme="finlaymacklon/boxy_violet",
|
53 |
+
).launch()
|