ccclemenfff commited on
Commit
cff733f
·
1 Parent(s): 4a7e273

add some debug information in handler.py

Browse files
Files changed (1) hide show
  1. handler.py +27 -5
handler.py CHANGED
@@ -41,6 +41,8 @@ class EndpointHandler:
41
  image_input = data.get("image", None)
42
  video_input = data.get("video", None)
43
 
 
 
44
  # 判断image输入是路径还是base64字符串
45
  if image_input:
46
  if os.path.exists(image_input):
@@ -59,19 +61,39 @@ class EndpointHandler:
59
  self.vision_feature = self.chat.get_video_embedding(video_input)
60
  else:
61
  tmp_path = save_base64_to_tempfile(video_input, suffix=".mp4")
 
62
  self.vision_feature = self.chat.get_video_embedding(tmp_path)
63
  os.unlink(tmp_path)
64
  self.modal_type = "video"
65
  self.chat.conv = get_conv_template("husky").copy()
 
 
 
 
 
 
66
 
67
  else:
68
  self.modal_type = "text"
69
  self.vision_feature = None
70
 
71
- conversations = self.chat.ask(prompt, self.chat.conv, modal_type=self.modal_type)
72
- output = self.chat.answer(conversations, self.vision_feature, modal_type=self.modal_type)
 
 
 
 
 
 
 
 
73
 
74
- # 更新对话历史
75
- self.chat.conv.messages[-1][1] = output.strip()
76
 
77
- return {"output": output.strip()}
 
 
 
 
 
 
41
  image_input = data.get("image", None)
42
  video_input = data.get("video", None)
43
 
44
+ print("📨 收到 prompt:", repr(prompt)) # 打印 prompt 内容
45
+
46
  # 判断image输入是路径还是base64字符串
47
  if image_input:
48
  if os.path.exists(image_input):
 
61
  self.vision_feature = self.chat.get_video_embedding(video_input)
62
  else:
63
  tmp_path = save_base64_to_tempfile(video_input, suffix=".mp4")
64
+ print("📼 保存临时视频路径:", tmp_path)
65
  self.vision_feature = self.chat.get_video_embedding(tmp_path)
66
  os.unlink(tmp_path)
67
  self.modal_type = "video"
68
  self.chat.conv = get_conv_template("husky").copy()
69
+
70
+ # 🔍 打印中间处理的 video_tensor shape
71
+ if isinstance(self.vision_feature, torch.Tensor):
72
+ print("📏 视觉特征张量 shape:", self.vision_feature.shape)
73
+ else:
74
+ print("❌ self.vision_feature 不是张量,类型:", type(self.vision_feature))
75
 
76
  else:
77
  self.modal_type = "text"
78
  self.vision_feature = None
79
 
80
+ try:
81
+ # 打印视觉特征存在与否
82
+ print("🧠 当前 modal_type:", self.modal_type)
83
+ print("🧠 是否有视觉特征:", self.vision_feature is not None)
84
+
85
+ conversations = self.chat.ask(prompt, self.chat.conv, modal_type=self.modal_type)
86
+ output = self.chat.answer(conversations, self.vision_feature, modal_type=self.modal_type)
87
+
88
+ # ✅ 打印 chat.answer 结果
89
+ print("📤 推理输出:", repr(output.strip()))
90
 
91
+ self.chat.conv.messages[-1][1] = output.strip()
92
+ return {"output": output.strip()}
93
 
94
+ except Exception as e:
95
+ # 🧨 如果出错,打印详细报错信息
96
+ import traceback
97
+ print("❌ 推理出错:")
98
+ traceback.print_exc()
99
+ return {"error": str(e)}