Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
f0f354e
1
Parent(s):
d84fba9
Refactor predict function to clean up history logging and improve pixel value logging
Browse files
app.py
CHANGED
@@ -195,12 +195,11 @@ def predict(message,
|
|
195 |
repetition_penalty=2.5,
|
196 |
do_sample=False):
|
197 |
|
198 |
-
history = state.get_prompt()[:-1]
|
199 |
-
logger.info(f"==== History ====\n{history}")
|
200 |
|
201 |
generation_config = dict(temperature=temperature, max_new_tokens= max_output_tokens, top_p=top_p, do_sample=do_sample, num_beams = 3, repetition_penalty=repetition_penalty)
|
202 |
|
203 |
-
question = message
|
204 |
pixel_values = None
|
205 |
if image_path is not None:
|
206 |
pixel_values = load_image(image_path, max_num=max_input_tiles).to(torch.bfloat16).cuda()
|
@@ -211,11 +210,13 @@ def predict(message,
|
|
211 |
DEFAULT_IMAGE_TOKEN not in first_user_message:
|
212 |
state.messages[index]['content'] = DEFAULT_IMAGE_TOKEN + "\n" + first_user_message
|
213 |
|
214 |
-
|
215 |
-
|
216 |
|
217 |
logger.info(f"==== Lenght Pixel values ====\n{len(pixel_values)}")
|
218 |
-
|
|
|
|
|
219 |
return response, conv_history
|
220 |
|
221 |
def ai_bot(
|
|
|
195 |
repetition_penalty=2.5,
|
196 |
do_sample=False):
|
197 |
|
198 |
+
# history = state.get_prompt()[:-1]
|
199 |
+
# logger.info(f"==== History ====\n{history}")
|
200 |
|
201 |
generation_config = dict(temperature=temperature, max_new_tokens= max_output_tokens, top_p=top_p, do_sample=do_sample, num_beams = 3, repetition_penalty=repetition_penalty)
|
202 |
|
|
|
203 |
pixel_values = None
|
204 |
if image_path is not None:
|
205 |
pixel_values = load_image(image_path, max_num=max_input_tiles).to(torch.bfloat16).cuda()
|
|
|
210 |
DEFAULT_IMAGE_TOKEN not in first_user_message:
|
211 |
state.messages[index]['content'] = DEFAULT_IMAGE_TOKEN + "\n" + first_user_message
|
212 |
|
213 |
+
history = state.get_prompt()[:-1]
|
214 |
+
logger.info(f"==== History ====\n{history}")
|
215 |
|
216 |
logger.info(f"==== Lenght Pixel values ====\n{len(pixel_values)}")
|
217 |
+
|
218 |
+
response, conv_history = model.chat(tokenizer, pixel_values, message, generation_config, history=history, return_history=True)
|
219 |
+
logger.info(f"==== Conv History ====\n{conv_history}")
|
220 |
return response, conv_history
|
221 |
|
222 |
def ai_bot(
|