warshanks commited on
Commit
e6496aa
·
verified ·
1 Parent(s): 307666a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -111,7 +111,7 @@ def process_video(video_path: str) -> list[dict]:
111
  with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
112
  pil_image.save(temp_file.name)
113
  content.append({"type": "text", "text": f"Frame {timestamp}:"})
114
- content.append({"type": "image", "url": temp_file.name})
115
  logger.debug(f"{content=}")
116
  return content
117
 
@@ -126,7 +126,7 @@ def process_interleaved_images(message: dict) -> list[dict]:
126
  for part in parts:
127
  logger.debug(f"{part=}")
128
  if part == "<image>":
129
- content.append({"type": "image", "url": message["files"][image_index]})
130
  logger.debug(f"file: {message['files'][image_index]}")
131
  image_index += 1
132
  elif part.strip():
@@ -145,11 +145,9 @@ def process_new_user_message(message: dict) -> list[dict]:
145
  return [{"type": "text", "text": message["text"]}, *process_video(message["files"][0])]
146
 
147
  if "<image>" in message["text"]:
148
- return process_interleaved_images(message)
149
-
150
- return [
151
  {"type": "text", "text": message["text"]},
152
- *[{"type": "image", "url": path} for path in message["files"]],
153
  ]
154
 
155
 
@@ -167,7 +165,7 @@ def process_history(history: list[dict]) -> list[dict]:
167
  if isinstance(content, str):
168
  current_user_content.append({"type": "text", "text": content})
169
  else:
170
- current_user_content.append({"type": "image", "url": content[0]})
171
  return messages
172
 
173
 
@@ -240,4 +238,4 @@ demo = gr.ChatInterface(
240
  )
241
 
242
  if __name__ == "__main__":
243
- demo.launch()
 
111
  with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
112
  pil_image.save(temp_file.name)
113
  content.append({"type": "text", "text": f"Frame {timestamp}:"})
114
+ content.append({"type": "image", "image": temp_file.name})
115
  logger.debug(f"{content=}")
116
  return content
117
 
 
126
  for part in parts:
127
  logger.debug(f"{part=}")
128
  if part == "<image>":
129
+ content.append({"type": "image", "image": message["files"][image_index]})
130
  logger.debug(f"file: {message['files'][image_index]}")
131
  image_index += 1
132
  elif part.strip():
 
145
  return [{"type": "text", "text": message["text"]}, *process_video(message["files"][0])]
146
 
147
  if "<image>" in message["text"]:
148
+ return process_interleaved_images(message) return [
 
 
149
  {"type": "text", "text": message["text"]},
150
+ *[{"type": "image", "image": path} for path in message["files"]],
151
  ]
152
 
153
 
 
165
  if isinstance(content, str):
166
  current_user_content.append({"type": "text", "text": content})
167
  else:
168
+ current_user_content.append({"type": "image", "image": content[0]})
169
  return messages
170
 
171
 
 
238
  )
239
 
240
  if __name__ == "__main__":
241
+ demo.launch()