NicolasCC commited on
Commit
941fb44
·
verified ·
1 Parent(s): abbb17f

Deploy CameraVLM demo

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -76,29 +76,36 @@ def upload_video(history, video):
76
  return (*show_chat(history), video)
77
 
78
 
79
- def add_message(history, video, message):
80
- """Appends the attached video (if any) and the question; a new video replaces the current one."""
81
- files, text = message.get("files") or [], (message.get("text") or "").strip()
82
  if files:
83
  video = files[-1]
84
  history = history + [{"role": "user", "content": {"path": video}}]
85
- request = None
 
 
 
 
 
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 files else message))
93
 
94
 
95
  def add_camera_motion(history, video, message):
96
- chat, upload, video, _, cleared = add_message(history, video, {"files": (message or {}).get("files")})
97
  if not video:
98
  gr.Warning("Please upload a video first.")
99
- return chat, upload, video, None, cleared
100
- history = chat.value + [{"role": "user", "content": "Describe the camera motion."}]
101
- return (*show_chat(history), video, ("camera_motion", ""), cleared)
 
 
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):