nroggendorff commited on
Commit
d6a5549
1 Parent(s): 5c1fa89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -24,21 +24,23 @@ def predict(message, history):
24
  "cognitivecomputations/dolphin-2.8-mistral-7b-v02",
25
  trust_remote_code=True
26
  )
 
27
  model = AutoModelForCausalLM.from_pretrained(
28
  "cognitivecomputations/dolphin-2.8-mistral-7b-v02",
29
  torch_dtype="auto",
30
  load_in_4bit=True,
31
  trust_remote_code=True
32
  )
33
- history_transformer_format = history + [[message, ""]]
34
 
 
35
  system_prompt = "<|im_start|>system\nYou are discord user Jimmy Donaldson. You are an american youtuber by the name of MrBeast. Your sole purpose in life is to get people to laugh at you. You make innapropriate jokes, and aren't very funny.<|im_end|>"
 
36
  messages = system_prompt + "".join(["".join(["\n<|im_start|>user\n" + item[0], "<|im_end|>\n<|im_start|>assistant\n" + item[1]]) for item in history_transformer_format])
37
- input_ids = tokenizer([messages], return_tensors="pt").to('cuda')
38
- streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
39
- generate_kwargs = dict(
 
40
  input_ids,
41
- streamer=streamer,
42
  max_new_tokens=10000,
43
  do_sample=True,
44
  top_p=0.95,
@@ -46,16 +48,9 @@ def predict(message, history):
46
  temperature=0.7,
47
  num_beams=1
48
  )
49
- t = Thread(target=model.generate, kwargs=generate_kwargs)
50
- t.start()
51
-
52
- final_message = []
53
- for new_token in streamer:
54
- final_message.append(new_token)
55
- if '<|im_end|>' in new_token:
56
- break
57
-
58
- return ''.join(final_message)
59
 
60
  @spaces.GPU(duration=120)
61
  def generate(content):
 
24
  "cognitivecomputations/dolphin-2.8-mistral-7b-v02",
25
  trust_remote_code=True
26
  )
27
+
28
  model = AutoModelForCausalLM.from_pretrained(
29
  "cognitivecomputations/dolphin-2.8-mistral-7b-v02",
30
  torch_dtype="auto",
31
  load_in_4bit=True,
32
  trust_remote_code=True
33
  )
 
34
 
35
+ history_transformer_format = history + [[message, ""]]
36
  system_prompt = "<|im_start|>system\nYou are discord user Jimmy Donaldson. You are an american youtuber by the name of MrBeast. Your sole purpose in life is to get people to laugh at you. You make innapropriate jokes, and aren't very funny.<|im_end|>"
37
+
38
  messages = system_prompt + "".join(["".join(["\n<|im_start|>user\n" + item[0], "<|im_end|>\n<|im_start|>assistant\n" + item[1]]) for item in history_transformer_format])
39
+
40
+ input_ids = tokenizer([messages], return_tensors="pt").to('cuda').input_ids
41
+
42
+ output_ids = model.generate(
43
  input_ids,
 
44
  max_new_tokens=10000,
45
  do_sample=True,
46
  top_p=0.95,
 
48
  temperature=0.7,
49
  num_beams=1
50
  )
51
+
52
+ output_text = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
53
+ return output_text
 
 
 
 
 
 
 
54
 
55
  @spaces.GPU(duration=120)
56
  def generate(content):