Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
|
3 |
import random
|
4 |
|
5 |
# Загрузка модели и токенизатора
|
6 |
-
model_name = "ai-forever/
|
7 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
8 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
9 |
|
@@ -16,9 +16,11 @@ def generate(prompt, _=None):
|
|
16 |
random_phrase = random.choice(random_phrases)
|
17 |
user_input = f"[USER]: {prompt}\n[BOT]: {random_phrase},"
|
18 |
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
19 |
-
outputs = model.generate(inputs, max_length=
|
20 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
edit_response = response.split(f"[BOT]: ")[-1].strip()
|
|
|
|
|
22 |
bot_message = f"[BOT!]: {edit_response}"
|
23 |
return bot_message
|
24 |
|
|
|
3 |
import random
|
4 |
|
5 |
# Загрузка модели и токенизатора
|
6 |
+
model_name = "ai-forever/rugpt3large_based_on_gpt2"
|
7 |
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
8 |
model = GPT2LMHeadModel.from_pretrained(model_name)
|
9 |
|
|
|
16 |
random_phrase = random.choice(random_phrases)
|
17 |
user_input = f"[USER]: {prompt}\n[BOT]: {random_phrase},"
|
18 |
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
19 |
+
outputs = model.generate(inputs, max_length=25, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
|
20 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
edit_response = response.split(f"[BOT]: ")[-1].strip()
|
22 |
+
if "[" in edit_response:
|
23 |
+
edit_response = edit_response.split("[")[0]
|
24 |
bot_message = f"[BOT!]: {edit_response}"
|
25 |
return bot_message
|
26 |
|