tanyuzhou commited on
Commit
beb3558
β€’
1 Parent(s): 608c2f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -3,12 +3,21 @@ import gradio as gr
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
5
  from transformers import TextStreamer
 
6
 
7
  import spaces
8
 
 
9
  tokenizer = AutoTokenizer.from_pretrained("Rorical/0-roleplay", trust_remote_code=True)
10
  tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + ((message['role'] + ':\n') if message['role'] != '' else '') + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>ζ˜Ÿι‡Ž:\n' }}{% endif %}" # Be careful that this model used custom chat template.
11
 
 
 
 
 
 
 
 
12
  # Define the response function
13
  @spaces.GPU
14
  def respond(
@@ -19,9 +28,6 @@ def respond(
19
  temperature,
20
  top_p,
21
  ):
22
- # Load model and tokenizer
23
- model = AutoModelForCausalLM.from_pretrained("Rorical/0-roleplay", return_dict=True, trust_remote_code=True)
24
-
25
  # Construct the messages for the chat
26
  messages = [{"role": "", "content": system_message}]
27
  for user_message, bot_response in history:
 
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
5
  from transformers import TextStreamer
6
+ import transformers
7
 
8
  import spaces
9
 
10
+ # Load tokenizer
11
  tokenizer = AutoTokenizer.from_pretrained("Rorical/0-roleplay", trust_remote_code=True)
12
  tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + ((message['role'] + ':\n') if message['role'] != '' else '') + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>ζ˜Ÿι‡Ž:\n' }}{% endif %}" # Be careful that this model used custom chat template.
13
 
14
+ # Load model
15
+ @spaces.GPU
16
+ def load_pretrained_model():
17
+ return AutoModelForCausalLM.from_pretrained("Rorical/0-roleplay", return_dict=True, trust_remote_code=True)
18
+
19
+ model = load_pretrained_model()
20
+
21
  # Define the response function
22
  @spaces.GPU
23
  def respond(
 
28
  temperature,
29
  top_p,
30
  ):
 
 
 
31
  # Construct the messages for the chat
32
  messages = [{"role": "", "content": system_message}]
33
  for user_message, bot_response in history: