Spaces:
Running
Running
Replace print with loguru
Browse files- app.py +7 -6
- pyproject.toml +1 -0
- requirements.txt +2 -0
- uv.lock +24 -0
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import cv2
|
|
| 9 |
import gradio as gr
|
| 10 |
import spaces
|
| 11 |
import torch
|
|
|
|
| 12 |
from PIL import Image
|
| 13 |
from transformers import AutoProcessor, Gemma3ForConditionalGeneration, TextIteratorStreamer
|
| 14 |
|
|
@@ -44,21 +45,21 @@ def process_new_user_message(message: dict) -> list[dict]:
|
|
| 44 |
if message["files"]:
|
| 45 |
if "<image>" in message["text"]:
|
| 46 |
content = []
|
| 47 |
-
|
| 48 |
parts = re.split(r"(<image>)", message["text"])
|
| 49 |
image_index = 0
|
| 50 |
-
|
| 51 |
for part in parts:
|
| 52 |
-
|
| 53 |
if part == "<image>":
|
| 54 |
content.append({"type": "image", "url": message["files"][image_index]})
|
| 55 |
-
|
| 56 |
image_index += 1
|
| 57 |
elif part.strip():
|
| 58 |
content.append({"type": "text", "text": part.strip()})
|
| 59 |
elif isinstance(part, str) and part != "<image>":
|
| 60 |
content.append({"type": "text", "text": part})
|
| 61 |
-
|
| 62 |
return content
|
| 63 |
if message["files"][0].endswith(".mp4"):
|
| 64 |
content = []
|
|
@@ -70,7 +71,7 @@ def process_new_user_message(message: dict) -> list[dict]:
|
|
| 70 |
pil_image.save(temp_file.name)
|
| 71 |
content.append({"type": "text", "text": f"Frame {timestamp}:"})
|
| 72 |
content.append({"type": "image", "url": temp_file.name})
|
| 73 |
-
|
| 74 |
return content
|
| 75 |
# non interleaved images
|
| 76 |
return [
|
|
|
|
| 9 |
import gradio as gr
|
| 10 |
import spaces
|
| 11 |
import torch
|
| 12 |
+
from loguru import logger
|
| 13 |
from PIL import Image
|
| 14 |
from transformers import AutoProcessor, Gemma3ForConditionalGeneration, TextIteratorStreamer
|
| 15 |
|
|
|
|
| 45 |
if message["files"]:
|
| 46 |
if "<image>" in message["text"]:
|
| 47 |
content = []
|
| 48 |
+
logger.debug(f"{message['files']=}")
|
| 49 |
parts = re.split(r"(<image>)", message["text"])
|
| 50 |
image_index = 0
|
| 51 |
+
logger.debug(f"{parts=}")
|
| 52 |
for part in parts:
|
| 53 |
+
logger.debug(f"{part=}")
|
| 54 |
if part == "<image>":
|
| 55 |
content.append({"type": "image", "url": message["files"][image_index]})
|
| 56 |
+
logger.debug(f"file: {message['files'][image_index]}")
|
| 57 |
image_index += 1
|
| 58 |
elif part.strip():
|
| 59 |
content.append({"type": "text", "text": part.strip()})
|
| 60 |
elif isinstance(part, str) and part != "<image>":
|
| 61 |
content.append({"type": "text", "text": part})
|
| 62 |
+
logger.debug(f"{content=}")
|
| 63 |
return content
|
| 64 |
if message["files"][0].endswith(".mp4"):
|
| 65 |
content = []
|
|
|
|
| 71 |
pil_image.save(temp_file.name)
|
| 72 |
content.append({"type": "text", "text": f"Frame {timestamp}:"})
|
| 73 |
content.append({"type": "image", "url": temp_file.name})
|
| 74 |
+
logger.debug(f"{content=}")
|
| 75 |
return content
|
| 76 |
# non interleaved images
|
| 77 |
return [
|
pyproject.toml
CHANGED
|
@@ -8,6 +8,7 @@ dependencies = [
|
|
| 8 |
"accelerate>=1.4.0",
|
| 9 |
"gradio>=5.20.1",
|
| 10 |
"hf-transfer>=0.1.9",
|
|
|
|
| 11 |
"opencv-python-headless>=4.11.0.86",
|
| 12 |
"protobuf>=6.30.0",
|
| 13 |
"sentencepiece>=0.2.0",
|
|
|
|
| 8 |
"accelerate>=1.4.0",
|
| 9 |
"gradio>=5.20.1",
|
| 10 |
"hf-transfer>=0.1.9",
|
| 11 |
+
"loguru>=0.7.3",
|
| 12 |
"opencv-python-headless>=4.11.0.86",
|
| 13 |
"protobuf>=6.30.0",
|
| 14 |
"sentencepiece>=0.2.0",
|
requirements.txt
CHANGED
|
@@ -77,6 +77,8 @@ jinja2==3.1.6
|
|
| 77 |
# via
|
| 78 |
# gradio
|
| 79 |
# torch
|
|
|
|
|
|
|
| 80 |
markdown-it-py==3.0.0
|
| 81 |
# via rich
|
| 82 |
markupsafe==2.1.5
|
|
|
|
| 77 |
# via
|
| 78 |
# gradio
|
| 79 |
# torch
|
| 80 |
+
loguru==0.7.3
|
| 81 |
+
# via gemma-3-12b-it (pyproject.toml)
|
| 82 |
markdown-it-py==3.0.0
|
| 83 |
# via rich
|
| 84 |
markupsafe==2.1.5
|
uv.lock
CHANGED
|
@@ -256,6 +256,7 @@ dependencies = [
|
|
| 256 |
{ name = "accelerate" },
|
| 257 |
{ name = "gradio" },
|
| 258 |
{ name = "hf-transfer" },
|
|
|
|
| 259 |
{ name = "opencv-python-headless" },
|
| 260 |
{ name = "protobuf" },
|
| 261 |
{ name = "sentencepiece" },
|
|
@@ -269,6 +270,7 @@ requires-dist = [
|
|
| 269 |
{ name = "accelerate", specifier = ">=1.4.0" },
|
| 270 |
{ name = "gradio", specifier = ">=5.20.1" },
|
| 271 |
{ name = "hf-transfer", specifier = ">=0.1.9" },
|
|
|
|
| 272 |
{ name = "opencv-python-headless", specifier = ">=4.11.0.86" },
|
| 273 |
{ name = "protobuf", specifier = ">=6.30.0" },
|
| 274 |
{ name = "sentencepiece", specifier = ">=0.2.0" },
|
|
@@ -450,6 +452,19 @@ wheels = [
|
|
| 450 |
{ url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899 },
|
| 451 |
]
|
| 452 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
[[package]]
|
| 454 |
name = "markdown-it-py"
|
| 455 |
version = "3.0.0"
|
|
@@ -1602,3 +1617,12 @@ wheels = [
|
|
| 1602 |
{ url = "https://files.pythonhosted.org/packages/68/a1/dcb68430b1d00b698ae7a7e0194433bce4f07ded185f0ee5fb21e2a2e91e/websockets-15.0.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:cad21560da69f4ce7658ca2cb83138fb4cf695a2ba3e475e0559e05991aa8122", size = 176884 },
|
| 1603 |
{ url = "https://files.pythonhosted.org/packages/fa/a8/5b41e0da817d64113292ab1f8247140aac61cbf6cfd085d6a0fa77f4984f/websockets-15.0.1-py3-none-any.whl", hash = "sha256:f7a866fbc1e97b5c617ee4116daaa09b722101d4a3c170c787450ba409f9736f", size = 169743 },
|
| 1604 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
{ name = "accelerate" },
|
| 257 |
{ name = "gradio" },
|
| 258 |
{ name = "hf-transfer" },
|
| 259 |
+
{ name = "loguru" },
|
| 260 |
{ name = "opencv-python-headless" },
|
| 261 |
{ name = "protobuf" },
|
| 262 |
{ name = "sentencepiece" },
|
|
|
|
| 270 |
{ name = "accelerate", specifier = ">=1.4.0" },
|
| 271 |
{ name = "gradio", specifier = ">=5.20.1" },
|
| 272 |
{ name = "hf-transfer", specifier = ">=0.1.9" },
|
| 273 |
+
{ name = "loguru", specifier = ">=0.7.3" },
|
| 274 |
{ name = "opencv-python-headless", specifier = ">=4.11.0.86" },
|
| 275 |
{ name = "protobuf", specifier = ">=6.30.0" },
|
| 276 |
{ name = "sentencepiece", specifier = ">=0.2.0" },
|
|
|
|
| 452 |
{ url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899 },
|
| 453 |
]
|
| 454 |
|
| 455 |
+
[[package]]
|
| 456 |
+
name = "loguru"
|
| 457 |
+
version = "0.7.3"
|
| 458 |
+
source = { registry = "https://pypi.org/simple" }
|
| 459 |
+
dependencies = [
|
| 460 |
+
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
| 461 |
+
{ name = "win32-setctime", marker = "sys_platform == 'win32'" },
|
| 462 |
+
]
|
| 463 |
+
sdist = { url = "https://files.pythonhosted.org/packages/3a/05/a1dae3dffd1116099471c643b8924f5aa6524411dc6c63fdae648c4f1aca/loguru-0.7.3.tar.gz", hash = "sha256:19480589e77d47b8d85b2c827ad95d49bf31b0dcde16593892eb51dd18706eb6", size = 63559 }
|
| 464 |
+
wheels = [
|
| 465 |
+
{ url = "https://files.pythonhosted.org/packages/0c/29/0348de65b8cc732daa3e33e67806420b2ae89bdce2b04af740289c5c6c8c/loguru-0.7.3-py3-none-any.whl", hash = "sha256:31a33c10c8e1e10422bfd431aeb5d351c7cf7fa671e3c4df004162264b28220c", size = 61595 },
|
| 466 |
+
]
|
| 467 |
+
|
| 468 |
[[package]]
|
| 469 |
name = "markdown-it-py"
|
| 470 |
version = "3.0.0"
|
|
|
|
| 1617 |
{ url = "https://files.pythonhosted.org/packages/68/a1/dcb68430b1d00b698ae7a7e0194433bce4f07ded185f0ee5fb21e2a2e91e/websockets-15.0.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:cad21560da69f4ce7658ca2cb83138fb4cf695a2ba3e475e0559e05991aa8122", size = 176884 },
|
| 1618 |
{ url = "https://files.pythonhosted.org/packages/fa/a8/5b41e0da817d64113292ab1f8247140aac61cbf6cfd085d6a0fa77f4984f/websockets-15.0.1-py3-none-any.whl", hash = "sha256:f7a866fbc1e97b5c617ee4116daaa09b722101d4a3c170c787450ba409f9736f", size = 169743 },
|
| 1619 |
]
|
| 1620 |
+
|
| 1621 |
+
[[package]]
|
| 1622 |
+
name = "win32-setctime"
|
| 1623 |
+
version = "1.2.0"
|
| 1624 |
+
source = { registry = "https://pypi.org/simple" }
|
| 1625 |
+
sdist = { url = "https://files.pythonhosted.org/packages/b3/8f/705086c9d734d3b663af0e9bb3d4de6578d08f46b1b101c2442fd9aecaa2/win32_setctime-1.2.0.tar.gz", hash = "sha256:ae1fdf948f5640aae05c511ade119313fb6a30d7eabe25fef9764dca5873c4c0", size = 4867 }
|
| 1626 |
+
wheels = [
|
| 1627 |
+
{ url = "https://files.pythonhosted.org/packages/e1/07/c6fe3ad3e685340704d314d765b7912993bcb8dc198f0e7a89382d37974b/win32_setctime-1.2.0-py3-none-any.whl", hash = "sha256:95d644c4e708aba81dc3704a116d8cbc974d70b3bdb8be1d150e36be6e9d1390", size = 4083 },
|
| 1628 |
+
]
|