Hank20041016 commited on
Commit
d8bdad3
·
verified ·
1 Parent(s): b44998f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -37,6 +37,14 @@ def predict(image_input, question):
37
 
38
  # 修正:使用 text 參數而不是直接傳遞 messages
39
  result = pipe(text=messages)
 
 
 
 
 
 
 
 
40
  return result[0]["generated_text"]
41
 
42
  # Gradio 介面(同時支援 UI 和 API)
@@ -49,5 +57,5 @@ iface = gr.Interface(
49
  )
50
 
51
  # 啟動應用程式
52
- if __name__ == "__main__":
53
  iface.launch()
 
37
 
38
  # 修正:使用 text 參數而不是直接傳遞 messages
39
  result = pipe(text=messages)
40
+
41
+ # 修正輸出格式:提取 assistant 的回應
42
+ if isinstance(result, list):
43
+ for message in result:
44
+ if isinstance(message, dict) and message.get("role") == "assistant":
45
+ return message.get("content", "")
46
+
47
+ # 備用方案
48
  return result[0]["generated_text"]
49
 
50
  # Gradio 介面(同時支援 UI 和 API)
 
57
  )
58
 
59
  # 啟動應用程式
60
+ if __name__ == "__main__": # 修正語法錯誤:__name__ 不是 **name**
61
  iface.launch()