XiaoBai1221 commited on
Commit
3a86301
·
1 Parent(s): 8b41cc3

Switch to gr.Interface to fix persistent schema errors

Browse files

- Replace complex gr.Blocks with simple gr.Interface
- Eliminate all potential sources of TypeError bool iteration
- Remove CSS themes and complex configurations
- Simplify component definitions to bare minimum
- Maintain core functionality with maximum compatibility

Files changed (1) hide show
  1. app.py +32 -95
app.py CHANGED
@@ -74,104 +74,41 @@ def clear_sequence():
74
  else:
75
  return "⚠️ 模型未載入"
76
 
77
- # 創建簡化的 Gradio 介面
78
- def create_interface():
79
- with gr.Blocks(
80
- title="SignView2.0 - 手語辨識系統",
81
- theme=gr.themes.Soft(),
82
- css="""
83
- .gradio-container {
84
- max-width: 1200px !important;
85
- }
86
- """
87
- ) as demo:
88
-
89
- gr.Markdown("""
90
- # 🤟 SignView2.0 - 手語辨識系統
91
-
92
- **支援34種手語詞彙的即時辨識系統,準確率達94.25%**
93
-
94
- ## 📋 支援詞彙
95
- again, all, apple, bad, bathroom, beautiful, bird, black, blue, book,
96
- bored, boy, brother, brown, but, computer, cousin, dance, day, deaf,
97
- doctor, dog, draw, drink, eat, english, family, father, fine, finish,
98
- fish, forget, friend, girl
99
-
100
- ## 🚀 使用說明
101
- 1. 上傳影像或使用攝像頭拍攝手語動作
102
- 2. 點擊「分析手語」按鈕
103
- 3. 查看辨識結果
104
- """)
105
-
106
- with gr.Row():
107
- with gr.Column():
108
- # 簡化的影像輸入 - 移除可能導致schema錯誤的複雜參數
109
- input_image = gr.Image(
110
- label="影像輸入",
111
- type="numpy",
112
- height=300
113
- )
114
-
115
- with gr.Row():
116
- process_btn = gr.Button("🔍 分析手語", variant="primary")
117
- clear_btn = gr.Button("🗑️ 清除序列", variant="secondary")
118
-
119
- with gr.Column():
120
- # 結果輸出
121
- output_image = gr.Image(
122
- label="辨識結果",
123
- type="numpy",
124
- height=300
125
- )
126
-
127
- prediction_text = gr.Textbox(
128
- label="預測結果",
129
- lines=8,
130
- value="等待影像輸入...",
131
- interactive=False
132
- )
133
-
134
- # 系統資訊
135
- gr.Markdown("""
136
- ## 📊 系統資訊
137
- - **模型準確率**: 94.25%
138
- - **F1分數**: 94.24%
139
- - **特徵提取**: MediaPipe + 光流
140
- - **模型架構**: BiLSTM + 注意力機制
141
- - **背景分割**: MediaPipe Segmentation
142
-
143
- **開發者**: XiaoBai1221 | **平台**: Hugging Face Spaces
144
- """)
145
-
146
- # 事件處理
147
- process_btn.click(
148
- fn=process_image,
149
- inputs=[input_image],
150
- outputs=[output_image, prediction_text],
151
- api_name="predict"
152
- )
153
-
154
- clear_btn.click(
155
- fn=clear_sequence,
156
- inputs=[],
157
- outputs=[prediction_text],
158
- api_name="clear"
159
- )
160
-
161
- return demo
162
 
163
  if __name__ == "__main__":
164
- # 啟動應用程式
165
  print("🎉 SignView2.0 手語辨識系統已啟動!")
166
 
167
- demo = create_interface()
168
-
169
- # 修復錯誤:設定share=True和其他參數
170
  demo.launch(
171
- share=True, # 解決localhost accessibility問題
172
- server_name="0.0.0.0", # 允許外部訪問
173
- server_port=7860, # 指定端口
174
- debug=False, # 避免debug模式的schema問題
175
- show_error=True, # 顯示錯誤訊息
176
- quiet=False # 顯示啟動訊息
177
  )
 
74
  else:
75
  return "⚠️ 模型未載入"
76
 
77
+ # 使用最簡單的Gradio介面來避免schema問題
78
+ title = "🤟 SignView2.0 - 手語辨識系統"
79
+ description = """
80
+ **支援34種手語詞彙的即時辨識系統,準確率達94.25%**
81
+
82
+ 📋 **支援詞彙**: again, all, apple, bad, bathroom, beautiful, bird, black, blue, book, bored, boy, brother, brown, but, computer, cousin, dance, day, deaf, doctor, dog, draw, drink, eat, english, family, father, fine, finish, fish, forget, friend, girl
83
+
84
+ 🚀 **使用說明**: 上傳影像 → 點擊分析 → 查看結果
85
+
86
+ 📊 **系統資訊**: 準確率94.25% | F1分數94.24% | MediaPipe + 光流特徵 | BiLSTM + 注意力機制
87
+ """
88
+
89
+ # 使用Interface而不是Blocks來避免複雜的schema問題
90
+ demo = gr.Interface(
91
+ fn=process_image,
92
+ inputs=gr.Image(label="上傳手語影像"),
93
+ outputs=[
94
+ gr.Image(label="辨識結果"),
95
+ gr.Textbox(label="預測結果", lines=6)
96
+ ],
97
+ title=title,
98
+ description=description,
99
+ examples=None,
100
+ cache_examples=False,
101
+ allow_flagging="never"
102
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
  if __name__ == "__main__":
 
105
  print("🎉 SignView2.0 手語辨識系統已啟動!")
106
 
107
+ # 使用最安全的launch參數
 
 
108
  demo.launch(
109
+ share=True,
110
+ server_name="0.0.0.0",
111
+ server_port=7860,
112
+ enable_queue=False,
113
+ show_error=True
 
114
  )