Update generate_game.py
Browse files- generate_game.py +5 -23
generate_game.py
CHANGED
@@ -1,28 +1,10 @@
|
|
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
-
import torch
|
3 |
|
4 |
-
# Загрузка
|
|
|
5 |
model_name = "mistralai/Mistral-7B-Instruct-v0.3"
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
12 |
-
outputs = model.generate(
|
13 |
-
inputs["input_ids"],
|
14 |
-
max_length=max_length,
|
15 |
-
num_return_sequences=1,
|
16 |
-
temperature=0.7,
|
17 |
-
top_p=0.9,
|
18 |
-
do_sample=True,
|
19 |
-
)
|
20 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
|
22 |
-
# Пример запроса
|
23 |
-
prompt = """
|
24 |
-
Создай простой код игры в стиле 2D RPG с использованием библиотеки Pygame.
|
25 |
-
Добавь игрока, монстров, систему здоровья и столкновений.
|
26 |
-
"""
|
27 |
-
game_code = generate_code(prompt)
|
28 |
-
print(game_code)
|
|
|
1 |
+
import os
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
3 |
|
4 |
+
# Загрузка токена из переменной окружения
|
5 |
+
hf_token = os.getenv("HUGGING_FACE_TOKEN")
|
6 |
model_name = "mistralai/Mistral-7B-Instruct-v0.3"
|
|
|
|
|
7 |
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|