vilarin commited on
Commit
6904764
1 Parent(s): de27ed6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -59,12 +59,13 @@ def stream_chat(message, history: list, temperature: float, max_new_tokens: int)
59
  conversation.append({"role": "user", "content": f"<|image_1|>\n{message['text']}"})
60
  else:
61
  if len(history) == 0:
62
- gr.Error("Please upload an image first.")
63
  image = None
64
  conversation.append({"role": "user", "content": message['text']})
65
-
66
- prompt = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
67
- inputs = processor(prompt, images=image, return_tensors="pt").to(0)
 
68
 
69
  generate_kwargs = dict(
70
  max_new_tokens=max_new_tokens,
@@ -74,7 +75,7 @@ def stream_chat(message, history: list, temperature: float, max_new_tokens: int)
74
  )
75
  if temperature == 0:
76
  generate_kwargs["do_sample"] = False
77
- generate_kwargs = {**inputs, **generate_kwargs}
78
 
79
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
80
 
 
59
  conversation.append({"role": "user", "content": f"<|image_1|>\n{message['text']}"})
60
  else:
61
  if len(history) == 0:
62
+ raise gr.Error("Please upload an image first.")
63
  image = None
64
  conversation.append({"role": "user", "content": message['text']})
65
+ print(conversation)
66
+
67
+ inputs = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
68
+ inputs_ids = processor(inputs, image, return_tensors="pt").to(0)
69
 
70
  generate_kwargs = dict(
71
  max_new_tokens=max_new_tokens,
 
75
  )
76
  if temperature == 0:
77
  generate_kwargs["do_sample"] = False
78
+ generate_kwargs = {**inputs_ids, **generate_kwargs}
79
 
80
  streamer = TextIteratorStreamer(processor, **{"skip_special_tokens": True, "skip_prompt": True, 'clean_up_tokenization_spaces':False,})
81