alfredplpl commited on
Commit
40e4ca6
Β·
verified Β·
1 Parent(s): fa77447

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -2
app.py CHANGED
@@ -47,6 +47,7 @@ h1 {
47
  tokenizer = AutoTokenizer.from_pretrained("alfredplpl/sarashina2-7b-it-test")
48
  model = AutoPeftModelForCausalLM.from_pretrained("alfredplpl/sarashina2-7b-it-test")
49
  tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}"
 
50
 
51
  @spaces.GPU()
52
  def chat_llama3_8b(message: str,
@@ -64,14 +65,12 @@ def chat_llama3_8b(message: str,
64
  Returns:
65
  str: The generated response.
66
  """
67
- global model
68
  conversation = []
69
  conversation.append({"role": "system", "content": "あγͺたはε„ͺ秀γͺγ‚’γ‚·γ‚Ήγ‚Ώγƒ³γƒˆγ§γ™γ€‚"})
70
  for user, assistant in history:
71
  conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
72
  conversation.append({"role": "user", "content": message})
73
 
74
- model=model.to("cuda:0")
75
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
76
 
77
  streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)
 
47
  tokenizer = AutoTokenizer.from_pretrained("alfredplpl/sarashina2-7b-it-test")
48
  model = AutoPeftModelForCausalLM.from_pretrained("alfredplpl/sarashina2-7b-it-test")
49
  tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}"
50
+ model=model.to("cuda:0")
51
 
52
  @spaces.GPU()
53
  def chat_llama3_8b(message: str,
 
65
  Returns:
66
  str: The generated response.
67
  """
 
68
  conversation = []
69
  conversation.append({"role": "system", "content": "あγͺたはε„ͺ秀γͺγ‚’γ‚·γ‚Ήγ‚Ώγƒ³γƒˆγ§γ™γ€‚"})
70
  for user, assistant in history:
71
  conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
72
  conversation.append({"role": "user", "content": message})
73
 
 
74
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
75
 
76
  streamer = TextIteratorStreamer(tokenizer, timeout=10.0, skip_prompt=True, skip_special_tokens=True)