Spaces:
Sleeping
Sleeping
Commit
·
64d50e5
1
Parent(s):
ba7ba17
Restore complete app.py with ultra-minimal Gradio config
Browse files- Add back full application code that was accidentally wiped
- Use minimal gr.Interface with string shortcuts to avoid schema bugs
- Single text output to prevent complex component issues
- Should finally resolve the persistent TypeError
app.py
CHANGED
|
@@ -1 +1,77 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# 檢查檔案是否存在
|
| 7 |
+
model_path = "tsflow/models/best_model.pt"
|
| 8 |
+
config_path = "tsflow/results/test_results.json"
|
| 9 |
+
|
| 10 |
+
# 如果是在SignView2.0目錄下運行,調整路徑
|
| 11 |
+
if not os.path.exists(model_path):
|
| 12 |
+
model_path = "../tsflow/models/best_model.pt"
|
| 13 |
+
config_path = "../tsflow/results/test_results.json"
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
from realtime_sign_prediction import RealtimeSignPredictor
|
| 17 |
+
|
| 18 |
+
# 初始化預測器
|
| 19 |
+
print("🚀 正在初始化手語辨識系統...")
|
| 20 |
+
predictor = RealtimeSignPredictor(
|
| 21 |
+
model_path=model_path,
|
| 22 |
+
config_path=config_path,
|
| 23 |
+
sequence_length=50,
|
| 24 |
+
use_segmentation=True
|
| 25 |
+
)
|
| 26 |
+
print("✅ 手語辨識系統初始化完成!")
|
| 27 |
+
MODEL_LOADED = True
|
| 28 |
+
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"⚠️ 模型載入失敗: {e}")
|
| 31 |
+
print("🔄 使用模擬模式運行...")
|
| 32 |
+
MODEL_LOADED = False
|
| 33 |
+
|
| 34 |
+
def predict_sign_language(image):
|
| 35 |
+
"""簡化的預測函數,返回單一字串結果"""
|
| 36 |
+
if image is None:
|
| 37 |
+
return "請上傳影像"
|
| 38 |
+
|
| 39 |
+
if not MODEL_LOADED:
|
| 40 |
+
return "⚠️ 模型未載入,無法進行預測"
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
# 處理畫面
|
| 44 |
+
results, keypoints, flow_features = predictor.process_frame(image)
|
| 45 |
+
|
| 46 |
+
# 獲取預測結果
|
| 47 |
+
top_predictions = predictor.get_top_predictions(top_k=3)
|
| 48 |
+
|
| 49 |
+
# 格式化預測結果為簡單字串
|
| 50 |
+
if top_predictions:
|
| 51 |
+
result_text = "🎯 手語辨識結果:\n\n"
|
| 52 |
+
for i, (label, confidence) in enumerate(top_predictions, 1):
|
| 53 |
+
result_text += f"{i}. {label}: {confidence:.2%}\n"
|
| 54 |
+
|
| 55 |
+
result_text += f"\n📊 序列進度: {len(predictor.keypoint_sequence)}/{predictor.sequence_length}"
|
| 56 |
+
else:
|
| 57 |
+
result_text = "📡 正在收集動作序列...\n請確保手語動作清晰可見"
|
| 58 |
+
|
| 59 |
+
return result_text
|
| 60 |
+
|
| 61 |
+
except Exception as e:
|
| 62 |
+
return f"❌ 處理錯誤: {str(e)}"
|
| 63 |
+
|
| 64 |
+
# 使用最基本的Interface配置,完全避免複雜參數
|
| 65 |
+
demo = gr.Interface(
|
| 66 |
+
fn=predict_sign_language,
|
| 67 |
+
inputs="image", # 使用字串而不是元件物件
|
| 68 |
+
outputs="text", # 使用字串而不是元件物件
|
| 69 |
+
title="🤟 SignView2.0 - 手語辨識系統",
|
| 70 |
+
description="支援34種手語詞彙的即時辨識系統,準確率達94.25%\n\n上傳影像即可開始辨識手語動作"
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
print("🎉 SignView2.0 手語辨識系統已啟動!")
|
| 75 |
+
|
| 76 |
+
# 使用最安全的launch配置
|
| 77 |
+
demo.launch()
|