XiaoBai1221 commited on
Commit
70c378e
·
1 Parent(s): 35d308c

修復 Gradio 4.44.x 兼容性 - 使用 Image 組件替代 Video,移除 streaming 參數

Browse files
Files changed (1) hide show
  1. app.py +27 -18
app.py CHANGED
@@ -65,7 +65,7 @@ def clear_predictions():
65
  """清除預測的包裝函數"""
66
  return global_predictor.clear_predictions()
67
 
68
- # 創建 Gradio 介面
69
  with gr.Blocks(
70
  title="SignView2.0 - 手語辨識系統",
71
  theme=gr.themes.Soft(),
@@ -94,22 +94,27 @@ with gr.Blocks(
94
  `fish`, `forget`, `friend`, `girl`
95
 
96
  ## 🚀 使用說明
97
- 1. 點擊下方攝像頭區域允許權限
98
- 2. 在攝像頭前做手語動作
99
- 3. 系統會即時顯示辨識結果
100
- 4. 點擊「清除預測」重新開始
101
  """, elem_classes=["header"])
102
 
103
  with gr.Row():
104
  with gr.Column(scale=2):
105
- # 視訊輸入
106
- video_input = gr.Video(
107
- label="📹 攝像頭輸入",
108
- sources=["webcam"],
109
- streaming=True,
110
  height=400
111
  )
112
 
 
 
 
 
 
 
 
113
  # 清除按鈕
114
  clear_btn = gr.Button(
115
  "🗑️ 清除預測序列",
@@ -118,11 +123,17 @@ with gr.Blocks(
118
  )
119
 
120
  with gr.Column(scale=1):
 
 
 
 
 
 
121
  # 預測輸出
122
  prediction_output = gr.Textbox(
123
- label="🎯 辨識結果",
124
- lines=12,
125
- value="等待攝像頭輸入...",
126
  elem_classes=["prediction-box"]
127
  )
128
 
@@ -144,12 +155,10 @@ with gr.Blocks(
144
  """)
145
 
146
  # 事件處理器
147
- video_input.stream(
148
  fn=process_video_frame,
149
- inputs=[video_input],
150
- outputs=[video_input, prediction_output],
151
- stream_every=0.1,
152
- show_progress=False
153
  )
154
 
155
  clear_btn.click(
 
65
  """清除預測的包裝函數"""
66
  return global_predictor.clear_predictions()
67
 
68
+ # 創建 Gradio 介面 - 修復 Gradio 4.44.x 兼容性
69
  with gr.Blocks(
70
  title="SignView2.0 - 手語辨識系統",
71
  theme=gr.themes.Soft(),
 
94
  `fish`, `forget`, `friend`, `girl`
95
 
96
  ## 🚀 使用說明
97
+ 1. 上傳影像或使用攝像頭拍攝手語動作
98
+ 2. 系統會自動辨識並顯示結果
99
+ 3. 點擊「清除預測」重新開始
 
100
  """, elem_classes=["header"])
101
 
102
  with gr.Row():
103
  with gr.Column(scale=2):
104
+ # 影像輸入 - 使用 Image 組件解決 Gradio 4.44.x 兼容性問題
105
+ image_input = gr.Image(
106
+ label="📹 影像輸入 (攝像頭/上傳)",
107
+ sources=["webcam", "upload"],
 
108
  height=400
109
  )
110
 
111
+ # 處理按鈕
112
+ process_btn = gr.Button(
113
+ "🔍 分析手語動作",
114
+ variant="primary",
115
+ size="lg"
116
+ )
117
+
118
  # 清除按鈕
119
  clear_btn = gr.Button(
120
  "🗑️ 清除預測序列",
 
123
  )
124
 
125
  with gr.Column(scale=1):
126
+ # 處理後的影像輸出
127
+ output_image = gr.Image(
128
+ label="🎯 辨識結果影像",
129
+ height=400
130
+ )
131
+
132
  # 預測輸出
133
  prediction_output = gr.Textbox(
134
+ label="📊 辨識結果",
135
+ lines=8,
136
+ value="等待影像輸入...",
137
  elem_classes=["prediction-box"]
138
  )
139
 
 
155
  """)
156
 
157
  # 事件處理器
158
+ process_btn.click(
159
  fn=process_video_frame,
160
+ inputs=[image_input],
161
+ outputs=[output_image, prediction_output]
 
 
162
  )
163
 
164
  clear_btn.click(