Deploy CameraVLM demo
Browse files
app.py
CHANGED
|
@@ -76,29 +76,36 @@ def upload_video(history, video):
|
|
| 76 |
return (*show_chat(history), video)
|
| 77 |
|
| 78 |
|
| 79 |
-
def
|
| 80 |
-
"""Appends
|
| 81 |
-
files
|
| 82 |
if files:
|
| 83 |
video = files[-1]
|
| 84 |
history = history + [{"role": "user", "content": {"path": video}}]
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
if text:
|
| 87 |
if video:
|
| 88 |
history = history + [{"role": "user", "content": text}]
|
| 89 |
request = ("question", text)
|
| 90 |
else:
|
| 91 |
gr.Warning("Please upload a video first.")
|
| 92 |
-
return (*show_chat(history), video, request, gr.MultimodalTextbox(value=None if request or
|
| 93 |
|
| 94 |
|
| 95 |
def add_camera_motion(history, video, message):
|
| 96 |
-
|
| 97 |
if not video:
|
| 98 |
gr.Warning("Please upload a video first.")
|
| 99 |
-
return
|
| 100 |
-
history =
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
def respond(history, video, request, num_frames):
|
|
|
|
| 76 |
return (*show_chat(history), video)
|
| 77 |
|
| 78 |
|
| 79 |
+
def attach_files(history, video, message):
|
| 80 |
+
"""Appends a video attached in the input box (if any); a new video replaces the current one."""
|
| 81 |
+
files = (message or {}).get("files") or []
|
| 82 |
if files:
|
| 83 |
video = files[-1]
|
| 84 |
history = history + [{"role": "user", "content": {"path": video}}]
|
| 85 |
+
return history, video, bool(files)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def add_message(history, video, message):
|
| 89 |
+
history, video, attached = attach_files(history, video, message)
|
| 90 |
+
text, request = ((message or {}).get("text") or "").strip(), None
|
| 91 |
if text:
|
| 92 |
if video:
|
| 93 |
history = history + [{"role": "user", "content": text}]
|
| 94 |
request = ("question", text)
|
| 95 |
else:
|
| 96 |
gr.Warning("Please upload a video first.")
|
| 97 |
+
return (*show_chat(history), video, request, gr.MultimodalTextbox(value=None if request or attached else message))
|
| 98 |
|
| 99 |
|
| 100 |
def add_camera_motion(history, video, message):
|
| 101 |
+
history, video, attached = attach_files(history, video, message)
|
| 102 |
if not video:
|
| 103 |
gr.Warning("Please upload a video first.")
|
| 104 |
+
return (*show_chat(history), video, None, gr.MultimodalTextbox(value=message))
|
| 105 |
+
history = history + [{"role": "user", "content": "Describe the camera motion."}]
|
| 106 |
+
# Keep any typed question in the box; only the attached file is consumed.
|
| 107 |
+
keep = {"text": (message or {}).get("text") or "", "files": []} if attached else message
|
| 108 |
+
return (*show_chat(history), video, ("camera_motion", ""), gr.MultimodalTextbox(value=keep))
|
| 109 |
|
| 110 |
|
| 111 |
def respond(history, video, request, num_frames):
|