osheina commited on
Commit
26c2790
·
verified ·
1 Parent(s): 473c0a0

Update pages/Camera.py

Browse files
Files changed (1) hide show
  1. pages/Camera.py +29 -29
pages/Camera.py CHANGED
@@ -9,7 +9,6 @@ from streamlit_webrtc import WebRtcMode, webrtc_streamer, RTCConfiguration
9
 
10
  from utils import SLInference
11
 
12
-
13
  logger = logging.getLogger(__name__)
14
 
15
  RTC_CONFIGURATION = RTCConfiguration({
@@ -17,9 +16,7 @@ RTC_CONFIGURATION = RTCConfiguration({
17
  })
18
 
19
  def main():
20
- """
21
- Main function of the app.
22
- """
23
  config = {
24
  "path_to_model": "S3D.onnx",
25
  "threshold": 0.3,
@@ -29,37 +26,35 @@ def main():
29
  "provider": "OpenVINOExecutionProvider"
30
  }
31
 
32
- # Сохранение конфигурации во временный файл
33
  with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.json') as config_file:
34
  json.dump(config, config_file)
35
  config_file_path = config_file.name
36
 
 
37
  inference_thread = SLInference(config_file_path)
38
  inference_thread.start()
39
 
 
 
 
 
 
 
 
 
 
40
  webrtc_ctx = webrtc_streamer(
41
- key="video-sendonly",
42
  mode=WebRtcMode.SENDONLY,
43
  rtc_configuration=RTC_CONFIGURATION,
44
  media_stream_constraints={"video": True, "audio": False},
45
  )
46
 
47
  gestures_deque = deque(maxlen=5)
48
-
49
- # Set up Streamlit interface
50
- st.title("Sign Language Recognition Demo")
51
  image_place = st.empty()
52
  text_output = st.empty()
53
- last_5_gestures = st.empty()
54
- st.markdown(
55
- """
56
- This application is designed to recognize sign language using a webcam feed.
57
- The model has been trained to recognize various sign language gestures and display the corresponding text in real-time.
58
-
59
-
60
- The project is open for collaboration. If you have any suggestions or want to contribute, please feel free to reach out.
61
- """
62
- )
63
 
64
  while True:
65
  if webrtc_ctx.video_receiver:
@@ -70,22 +65,27 @@ def main():
70
  continue
71
 
72
  img_rgb = video_frame.to_ndarray(format="rgb24")
73
- image_place.image(img_rgb)
74
- inference_thread.input_queue.append(video_frame.reformat(224, 224).to_ndarray(format="rgb24"))
75
 
 
 
76
  gesture = inference_thread.pred
 
77
  if gesture not in ['no', '']:
78
- if not gestures_deque:
79
- gestures_deque.append(gesture)
80
- elif gesture != gestures_deque[-1]:
81
  gestures_deque.append(gesture)
82
 
83
- text_output.markdown(f'<p style="font-size:20px"> Current gesture: {gesture}</p>',
84
- unsafe_allow_html=True)
85
- last_5_gestures.markdown(f'<p style="font-size:20px"> Last 5 gestures: {" ".join(gestures_deque)}</p>',
86
- unsafe_allow_html=True)
87
- print(gestures_deque)
 
 
 
 
88
 
89
  if __name__ == "__main__":
90
  main()
91
 
 
 
9
 
10
  from utils import SLInference
11
 
 
12
  logger = logging.getLogger(__name__)
13
 
14
  RTC_CONFIGURATION = RTCConfiguration({
 
16
  })
17
 
18
  def main():
19
+ # Конфигурация модели
 
 
20
  config = {
21
  "path_to_model": "S3D.onnx",
22
  "threshold": 0.3,
 
26
  "provider": "OpenVINOExecutionProvider"
27
  }
28
 
29
+ # Временный файл с конфигом
30
  with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.json') as config_file:
31
  json.dump(config, config_file)
32
  config_file_path = config_file.name
33
 
34
+ # Запуск инференса
35
  inference_thread = SLInference(config_file_path)
36
  inference_thread.start()
37
 
38
+ # --- Заголовок камеры в фирменном стиле ---
39
+ st.markdown("""
40
+ <div class="upload-section">
41
+ <h3>📷 Live Camera Recognition</h3>
42
+ <p>Enable your webcam and see real-time gesture detection powered by AI.</p>
43
+ </div>
44
+ """, unsafe_allow_html=True)
45
+
46
+ # Запуск WebRTC
47
  webrtc_ctx = webrtc_streamer(
48
+ key="gesture-stream",
49
  mode=WebRtcMode.SENDONLY,
50
  rtc_configuration=RTC_CONFIGURATION,
51
  media_stream_constraints={"video": True, "audio": False},
52
  )
53
 
54
  gestures_deque = deque(maxlen=5)
 
 
 
55
  image_place = st.empty()
56
  text_output = st.empty()
57
+ last_5_output = st.empty()
 
 
 
 
 
 
 
 
 
58
 
59
  while True:
60
  if webrtc_ctx.video_receiver:
 
65
  continue
66
 
67
  img_rgb = video_frame.to_ndarray(format="rgb24")
68
+ image_place.image(img_rgb, caption="📸 Live Feed", use_column_width=True)
 
69
 
70
+ # Инференс кадра
71
+ inference_thread.input_queue.append(video_frame.reformat(224, 224).to_ndarray(format="rgb24"))
72
  gesture = inference_thread.pred
73
+
74
  if gesture not in ['no', '']:
75
+ if not gestures_deque or gesture != gestures_deque[-1]:
 
 
76
  gestures_deque.append(gesture)
77
 
78
+ # Вывод на экран
79
+ text_output.markdown(
80
+ f'<div class="section"><p style="font-size:22px">🖐️ Current gesture: <b>{gesture}</b></p></div>',
81
+ unsafe_allow_html=True
82
+ )
83
+ last_5_output.markdown(
84
+ f'<div class="section"><p style="font-size:18px">🧠 Last 5 gestures: <span style="color:#6a1b9a;">{" | ".join(gestures_deque)}</span></p></div>',
85
+ unsafe_allow_html=True
86
+ )
87
 
88
  if __name__ == "__main__":
89
  main()
90
 
91
+