I'm facing a problem about Renpy that it won't recognize original python definition like this
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 44, in script
python:
File "game/script.rpy", line 47, in <module>
response = generate_text(message)
NameError: name 'generate_text' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 44, in script
python:
File "C:\Users\shion\OneDrive\desktop\renpy-8.1.3-sdk\renpy\ast.py", line 1138, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\shion\OneDrive\desktop\renpy-8.1.3-sdk\renpy\python.py", line 1122, in py_exec_bytecode
exec(bytecode, globals, locals)
File "game/script.rpy", line 47, in <module>
response = generate_text(message)
NameError: name 'generate_text' is not defined
Windows-10-10.0.22621 AMD64
Ren'Py 8.1.3.23091805
Live2D_AI 1.0
Wed Oct 25 00:44:38 2023
I tried several times to fix it but it won't work so I need help.
from transformers import AutoTokenizer, AutoModelForCausalLM
import sentencepiece
model_name = "C:/Users/shion/OneDrive/desktop/renpy-8.1.3-sdk/Live2D_AI/game/fine-tuned-model"
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left")
model = AutoModelForCausalLM.from_pretrained(model_name)
def generate_text(message, length=50):
input_ids = tokenizer.encode(message, return_tensors='pt', padding=True, truncation=True)
attention_mask = input_ids.ne(tokenizer.pad_token_id).float()
output = model.generate(
input_ids=input_ids,
max_length=length + len(input_ids[0]),
attention_mask=attention_mask,
pad_token_id=tokenizer.eos_token_id,
do_sample=True,
top_k=50,
top_p=0.95,
temperature=1.0,
num_return_sequences=1,
)
response = tokenizer.decode(output[0], skip_special_tokens=True)
return response
define e = Character("Hiyori")
define config.gl2 = True
image hiyori = Live2D("Resources/hiyori", base=.6, loop = True, fade=True)
label start:
$ renpy.block_rollback()
show hiyori m01
jump talk_keyboard
return
label talk_keyboard:
$ renpy.block_rollback()
show hiyori m02
python:
thinking = 0
message = renpy.input("You:")
response = generate_text(message)
if message.lower() == 'quit':
e "Goodbye!"
return
jump checkRes
label checkRes:
$ renpy.block_rollback()
if(thinking == 0):
show hiyori m03
python:
thinking = 0
e "[response]"
# jump answer
jump talk_keyboard
else:
$ renpy.block_rollback()
e "......"
$ thinking = 1
jump checkRes