DongfuJiang commited on
Commit
285e0ce
·
1 Parent(s): 9ae2aa9
Files changed (1) hide show
  1. app_idefics2.py +15 -6
app_idefics2.py CHANGED
@@ -74,16 +74,25 @@ def get_chat_history(history):
74
  "content": []
75
  }
76
  )
 
77
  assert num_images + cur_image_idx <= len(images), f"Number of images uploaded is less than the number of <image> placeholders in the text. Please upload more images."
78
  if num_images > 0:
79
- for sub_text in message[0].split("<image>"):
80
- if sub_text.strip():
81
- messages[-1]["content"].append({"type": "text", "text": sub_text.strip()})
82
- if cur_image_idx < len(images):
83
- messages[-1]["content"].append({"type": "image"})
84
- cur_image_idx += 1
 
85
  else:
86
  messages[-1]["content"].append({"type": "text", "text": message[0]})
 
 
 
 
 
 
 
87
  elif isinstance(message[0], tuple):
88
  pass
89
  return messages, images
 
74
  "content": []
75
  }
76
  )
77
+ print(num_images, cur_image_idx, len(images))
78
  assert num_images + cur_image_idx <= len(images), f"Number of images uploaded is less than the number of <image> placeholders in the text. Please upload more images."
79
  if num_images > 0:
80
+ split_text = message[0].split("<image>")
81
+ if split_text[0].strip():
82
+ messages[-1]["content"].append({"type": "text", "text": split_text[0].strip()})
83
+ for idx in range(num_images):
84
+ messages[-1]["content"].append({"type": "image"})
85
+ if split_text[idx + 1].strip():
86
+ messages[-1]["content"].append({"type": "text", "text": split_text[idx + 1].strip()})
87
  else:
88
  messages[-1]["content"].append({"type": "text", "text": message[0]})
89
+ if message[1]:
90
+ messages.append(
91
+ {
92
+ "role": "assistant",
93
+ "content": [{"type": "text", "text": message[1]}]
94
+ }
95
+ )
96
  elif isinstance(message[0], tuple):
97
  pass
98
  return messages, images