eddywu commited on
Commit
7dffdee
·
verified ·
1 Parent(s): c1bb76e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -175,7 +175,11 @@ def caption_video(video_path: str) -> str:
175
  return "No video provided."
176
 
177
  T = Timer()
 
 
178
  model, processor = _load_model_and_processor()
 
 
179
 
180
  print("[ENV] MAX_NEW_TOKENS =", MAX_NEW_TOKENS, flush=True)
181
  print("[CUDA] available =", torch.cuda.is_available(), flush=True)
@@ -263,6 +267,7 @@ def caption_video(video_path: str) -> str:
263
  skip_special_tokens=True,
264
  clean_up_tokenization_spaces=False
265
  )
 
266
  T.mark("postprocess_s", time.perf_counter()-t)
267
 
268
  # print
@@ -280,12 +285,20 @@ def caption_video(video_path: str) -> str:
280
  except Exception: pass
281
 
282
  # 打印詳細 timing 到日誌(HF Spaces Logs 可見)
283
- print({"timings": T.result(), "transcode": tr_info})
 
 
 
284
 
285
  caption = (output_text[0] if output_text else "").strip()
286
  if DEBUG_TIMINGS:
287
- rt = T.result()
288
- caption += f"\n\n[timings] total={rt['total_s']}s, transcode={rt.get('maybe_transcode_s','-')}s, preprocess={rt.get('preprocess_s','-')}s, generate={rt.get('generate_s','-')}s"
 
 
 
 
 
289
  return caption
290
 
291
  # Gradio 介面
 
175
  return "No video provided."
176
 
177
  T = Timer()
178
+
179
+ t = time.perf_counter()
180
  model, processor = _load_model_and_processor()
181
+ if torch.cuda.is_available(): torch.cuda.synchronize()
182
+ T.mark("load_model_s", time.perf_counter()-t)
183
 
184
  print("[ENV] MAX_NEW_TOKENS =", MAX_NEW_TOKENS, flush=True)
185
  print("[CUDA] available =", torch.cuda.is_available(), flush=True)
 
267
  skip_special_tokens=True,
268
  clean_up_tokenization_spaces=False
269
  )
270
+ if torch.cuda.is_available(): torch.cuda.synchronize()
271
  T.mark("postprocess_s", time.perf_counter()-t)
272
 
273
  # print
 
285
  except Exception: pass
286
 
287
  # 打印詳細 timing 到日誌(HF Spaces Logs 可見)
288
+ rt = T.result()
289
+ known = sum(v for k, v in rt.items() if k != "total_s")
290
+ other = round(rt["total_s"] - known, 3)
291
+ print({"timings": rt | {"other_s": other}, "transcode": tr_info}, flush=True)
292
 
293
  caption = (output_text[0] if output_text else "").strip()
294
  if DEBUG_TIMINGS:
295
+ caption += (
296
+ f"\n\n[timings] total={rt['total_s']}s, "
297
+ f"transcode={rt.get('maybe_transcode_s','-')}s, "
298
+ f"preprocess={rt.get('preprocess_s','-')}s, "
299
+ f"generate={rt.get('generate_s','-')}s, "
300
+ f"other={other}s"
301
+ )
302
  return caption
303
 
304
  # Gradio 介面