Spaces:
Sleeping
Sleeping
Commit
·
c4b1c9d
1
Parent(s):
64d50e5
ULTIMATE FIX: Switch to Blocks + HF Spaces detection
Browse files- Replace gr.Interface with gr.Blocks to avoid schema processing bugs
- Use direct image.change event instead of complex Interface schema
- Add SPACE_ID environment detection for proper HF Spaces handling
- Use server_name='0.0.0.0' for Spaces, share=True for local
- This should resolve both TypeError and localhost accessibility issues
- Reference: HF Forums discussion on Spaces launch problems
app.py
CHANGED
|
@@ -61,17 +61,26 @@ def predict_sign_language(image):
|
|
| 61 |
except Exception as e:
|
| 62 |
return f"❌ 處理錯誤: {str(e)}"
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
)
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
print("🎉 SignView2.0 手語辨識系統已啟動!")
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
return f"❌ 處理錯誤: {str(e)}"
|
| 63 |
|
| 64 |
+
# 創建最基本的Blocks介面來避開Interface的schema問題
|
| 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)
|