Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -31,6 +31,9 @@ processor = AutoProcessor.from_pretrained("lingshu-medical-mllm/Lingshu-7B")
|
|
31 |
MAX_NUM_IMAGES = int(os.getenv("MAX_NUM_IMAGES", "5"))
|
32 |
|
33 |
|
|
|
|
|
|
|
34 |
def count_files_in_new_message(paths: list[str]) -> tuple[int, int]:
|
35 |
image_count = 0
|
36 |
video_count = 0
|
@@ -111,7 +114,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", "
|
115 |
logger.debug(f"{content=}")
|
116 |
return content
|
117 |
|
@@ -126,7 +129,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", "
|
130 |
logger.debug(f"file: {message['files'][image_index]}")
|
131 |
image_index += 1
|
132 |
elif part.strip():
|
@@ -140,16 +143,13 @@ def process_interleaved_images(message: dict) -> list[dict]:
|
|
140 |
def process_new_user_message(message: dict) -> list[dict]:
|
141 |
if not message["files"]:
|
142 |
return [{"type": "text", "text": message["text"]}]
|
143 |
-
|
144 |
if message["files"][0].endswith(".mp4"):
|
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", "
|
153 |
]
|
154 |
|
155 |
|
@@ -167,7 +167,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", "
|
171 |
return messages
|
172 |
|
173 |
|
|
|
31 |
MAX_NUM_IMAGES = int(os.getenv("MAX_NUM_IMAGES", "5"))
|
32 |
|
33 |
|
34 |
+
MAX_NUM_IMAGES = int(os.getenv("MAX_NUM_IMAGES", "5"))
|
35 |
+
|
36 |
+
|
37 |
def count_files_in_new_message(paths: list[str]) -> tuple[int, int]:
|
38 |
image_count = 0
|
39 |
video_count = 0
|
|
|
114 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
115 |
pil_image.save(temp_file.name)
|
116 |
content.append({"type": "text", "text": f"Frame {timestamp}:"})
|
117 |
+
content.append({"type": "image", "image": temp_file.name})
|
118 |
logger.debug(f"{content=}")
|
119 |
return content
|
120 |
|
|
|
129 |
for part in parts:
|
130 |
logger.debug(f"{part=}")
|
131 |
if part == "<image>":
|
132 |
+
content.append({"type": "image", "image": message["files"][image_index]})
|
133 |
logger.debug(f"file: {message['files'][image_index]}")
|
134 |
image_index += 1
|
135 |
elif part.strip():
|
|
|
143 |
def process_new_user_message(message: dict) -> list[dict]:
|
144 |
if not message["files"]:
|
145 |
return [{"type": "text", "text": message["text"]}]
|
|
|
146 |
if message["files"][0].endswith(".mp4"):
|
147 |
return [{"type": "text", "text": message["text"]}, *process_video(message["files"][0])]
|
|
|
148 |
if "<image>" in message["text"]:
|
149 |
return process_interleaved_images(message)
|
|
|
150 |
return [
|
151 |
{"type": "text", "text": message["text"]},
|
152 |
+
*[{"type": "image", "image": path} for path in message["files"]],
|
153 |
]
|
154 |
|
155 |
|
|
|
167 |
if isinstance(content, str):
|
168 |
current_user_content.append({"type": "text", "text": content})
|
169 |
else:
|
170 |
+
current_user_content.append({"type": "image", "image": content[0]})
|
171 |
return messages
|
172 |
|
173 |
|