XiaoBai1221 commited on
Commit
d68547d
·
1 Parent(s): c4b1c9d

DOWNGRADE FIX: Rollback to Gradio 4.38.1 + Robust Launch

Browse files

- Downgrade to gradio==4.38.1 to avoid schema bug in 4.44.0
- Use simple gr.Interface with flagging_mode='never'
- Add multi-tier error handling for different environments
- Progressive fallback: default -> share=True -> server config
- This should resolve the persistent TypeError bool iteration issue
- Reference: GitHub issue #4046 about localhost accessibility

Files changed (2) hide show
  1. app.py +22 -18
  2. requirements.txt +1 -1
app.py CHANGED
@@ -61,26 +61,30 @@ def predict_sign_language(image):
61
  except Exception as e:
62
  return f"❌ 處理錯誤: {str(e)}"
63
 
64
- # 創建最基本的Blocks介面來避開Interfaceschema問題
65
- with gr.Blocks(title="SignView2.0 - 手語辨識系統") as demo:
66
- gr.Markdown("# 🤟 SignView2.0 - 手語辨識系統")
67
- gr.Markdown("支援34種手語詞彙的即時辨識系統,準確率達94.25%")
68
- gr.Markdown("上傳影像即可開始辨識手語動作")
69
-
70
- with gr.Row():
71
- image_input = gr.Image()
72
- text_output = gr.Textbox(label="辨識結果", lines=10)
73
-
74
- image_input.change(predict_sign_language, inputs=image_input, outputs=text_output)
75
 
76
  if __name__ == "__main__":
77
  print("🎉 SignView2.0 手語辨識系統已啟動!")
78
 
79
- # 針對Hugging Face Spaces的特殊配置
80
  import os
81
- if os.environ.get("SPACE_ID"):
82
- # 在Hugging Face Spaces上運行
83
- demo.launch(server_name="0.0.0.0", server_port=7860)
84
- else:
85
- # 本地運行
86
- demo.launch(share=True)
 
 
 
 
 
 
 
61
  except Exception as e:
62
  return f"❌ 處理錯誤: {str(e)}"
63
 
64
+ # 使用最簡單的Interface避開所有schema問題
65
+ demo = gr.Interface(
66
+ fn=predict_sign_language,
67
+ inputs=gr.Image(),
68
+ outputs=gr.Textbox(lines=10),
69
+ title="🤟 SignView2.0 - 手語辨識系統",
70
+ description="支援34種手語詞彙的即時辨識系統,準確率達94.25%\n\n上傳影像即可開始辨識手語動作",
71
+ flagging_mode="never"
72
+ )
 
 
73
 
74
  if __name__ == "__main__":
75
  print("🎉 SignView2.0 手語辨識系統已啟動!")
76
 
77
+ # 根據環境自動選擇最佳配置
78
  import os
79
+ try:
80
+ # 嘗試最簡單的launch,讓Gradio自己處理
81
+ demo.launch()
82
+ except Exception as e:
83
+ print(f"預設啟動失敗,嘗試備用方案: {e}")
84
+ try:
85
+ # 如果在Spaces環境,強制使用share=True
86
+ demo.launch(share=True)
87
+ except Exception as e2:
88
+ print(f"備用方案也失敗: {e2}")
89
+ # 最後嘗試基本配置
90
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==4.44.0
2
  torch>=2.0.0
3
  torchvision>=0.15.0
4
  opencv-python>=4.8.0
 
1
+ gradio==4.38.1
2
  torch>=2.0.0
3
  torchvision>=0.15.0
4
  opencv-python>=4.8.0