ysharma HF staff commited on
Commit
9fb87d0
1 Parent(s): ba436e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -6
app.py CHANGED
@@ -69,13 +69,11 @@ def bot_streaming(message, history):
69
  else:
70
  conversation.append({"role": "user", "content": message['text']})
71
  print(f"prompt is -\n{conversation}")
72
- #prompt = f"""User:<image>\n{message['text']} Falcon:"""
73
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
74
  image = Image.open(image)
75
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
76
- #inputs = processor(prompt, image, return_tensors='pt').to(0, torch.float16)
77
 
78
- streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,}) # "eos_token_id":processor.tokenizer.eos_token_id})
79
  generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024, do_sample=False, temperature=0.0, eos_token_id=processor.tokenizer.eos_token_id,)
80
 
81
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
@@ -83,9 +81,6 @@ def bot_streaming(message, history):
83
 
84
  buffer = ""
85
  for new_text in streamer:
86
- # find <|eot_id|> and remove it from the new_text
87
- #if "<|eot_id|>" in new_text:
88
- # new_text = new_text.split("<|eot_id|>")[0]
89
  buffer += new_text
90
  yield buffer
91
 
 
69
  else:
70
  conversation.append({"role": "user", "content": message['text']})
71
  print(f"prompt is -\n{conversation}")
 
72
  prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
73
  image = Image.open(image)
74
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
 
75
 
76
+ streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
77
  generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024, do_sample=False, temperature=0.0, eos_token_id=processor.tokenizer.eos_token_id,)
78
 
79
  thread = Thread(target=model.generate, kwargs=generation_kwargs)
 
81
 
82
  buffer = ""
83
  for new_text in streamer:
 
 
 
84
  buffer += new_text
85
  yield buffer
86