XiaoBai1221 commited on
Commit
ba7ba17
·
1 Parent(s): f2900ce

FINAL FIX: Ultra-minimal Gradio interface to avoid schema bugs

Browse files

- Strip down to bare minimum gr.Interface configuration
- Use string shortcuts ('image', 'text') instead of component objects
- Remove ALL complex parameters that trigger schema processing
- Simplify to single output text instead of dual outputs
- Eliminate any potential source of TypeError bool iteration
- This should definitively resolve the persistent schema error

Files changed (1) hide show
  1. app.py +1 -113
app.py CHANGED
@@ -1,113 +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 process_image(image):
35
- """處理上傳的影像"""
36
- if image is None:
37
- return None, "請上傳影像或使用攝像頭拍攝"
38
-
39
- if not MODEL_LOADED:
40
- return image, "⚠️ 模型未載入,無法進行預測\n請檢查模型檔案路徑"
41
-
42
- try:
43
- # 處理畫面
44
- results, keypoints, flow_features = predictor.process_frame(image)
45
-
46
- # 繪製關鍵點
47
- annotated_frame = predictor.draw_landmarks(image.copy(), results)
48
-
49
- # 獲取預測結果
50
- top_predictions = predictor.get_top_predictions(top_k=3)
51
-
52
- # 格式化預測結果
53
- if top_predictions:
54
- prediction_text = "🎯 手語辨識結果:\n\n"
55
- for i, (label, confidence) in enumerate(top_predictions, 1):
56
- prediction_text += f"{i}. {label}: {confidence:.2%}\n"
57
-
58
- # 添加序列資訊
59
- prediction_text += f"\n📊 序列進度: {len(predictor.keypoint_sequence)}/{predictor.sequence_length}"
60
- else:
61
- prediction_text = "📡 正在收集動作序列...\n請確保手語動作清晰可見"
62
-
63
- return annotated_frame, prediction_text
64
-
65
- except Exception as e:
66
- return image, f"❌ 處理錯誤: {str(e)}"
67
-
68
- def clear_sequence():
69
- """清除預測序列"""
70
- if MODEL_LOADED:
71
- predictor.keypoint_sequence.clear()
72
- predictor.flow_sequence.clear()
73
- return "✅ 已清除預測序列"
74
- else:
75
- return "⚠️ 模型未載入"
76
-
77
- # 使用最簡單且穩定的Gradio介面
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
- **開發者**: XiaoBai1221 | **平台**: Hugging Face Spaces
89
- """
90
-
91
- # 使用Interface來避免Blocks的複雜問題
92
- demo = gr.Interface(
93
- fn=process_image,
94
- inputs=gr.Image(label="上傳手語影像"),
95
- outputs=[
96
- gr.Image(label="辨識結果"),
97
- gr.Textbox(label="預測結果", lines=6)
98
- ],
99
- title=title,
100
- description=description,
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
- show_error=True
113
- )
 
1
+