Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ tokenizer = AutoTokenizer.from_pretrained("universitytehran/PersianMind-v1.0")
|
|
6 |
model = AutoModelForCausalLM.from_pretrained(
|
7 |
"universitytehran/PersianMind-v1.0",
|
8 |
torch_dtype=torch.bfloat16
|
9 |
-
).to("cpu")
|
10 |
|
11 |
CONTEXT = (
|
12 |
"This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
|
@@ -19,7 +19,8 @@ pretokenized_context = tokenizer(CONTEXT, return_tensors="pt").input_ids.to("cpu
|
|
19 |
|
20 |
def generate_response(message, chat_history):
|
21 |
|
22 |
-
|
|
|
23 |
[pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")],
|
24 |
dim=1
|
25 |
)
|
@@ -27,7 +28,7 @@ def generate_response(message, chat_history):
|
|
27 |
with torch.no_grad():
|
28 |
outputs = model.generate(
|
29 |
prompt,
|
30 |
-
max_new_tokens=64,
|
31 |
do_sample=True,
|
32 |
temperature=0.7,
|
33 |
top_k=40,
|
@@ -35,7 +36,7 @@ def generate_response(message, chat_history):
|
|
35 |
)
|
36 |
|
37 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
38 |
-
response = result.split("ParvizGPT:")[-1].strip()
|
39 |
return chat_history + [(message, response)]
|
40 |
|
41 |
|
|
|
6 |
model = AutoModelForCausalLM.from_pretrained(
|
7 |
"universitytehran/PersianMind-v1.0",
|
8 |
torch_dtype=torch.bfloat16
|
9 |
+
).to("cpu")
|
10 |
|
11 |
CONTEXT = (
|
12 |
"This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
|
|
|
19 |
|
20 |
def generate_response(message, chat_history):
|
21 |
|
22 |
+
|
23 |
+
prompt = torch.cat(
|
24 |
[pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")],
|
25 |
dim=1
|
26 |
)
|
|
|
28 |
with torch.no_grad():
|
29 |
outputs = model.generate(
|
30 |
prompt,
|
31 |
+
max_new_tokens=64,
|
32 |
do_sample=True,
|
33 |
temperature=0.7,
|
34 |
top_k=40,
|
|
|
36 |
)
|
37 |
|
38 |
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
39 |
+
response = result.split("ParvizGPT:")[-1].strip()
|
40 |
return chat_history + [(message, response)]
|
41 |
|
42 |
|