osheina commited on
Commit
7e1bc26
·
verified ·
1 Parent(s): 26c2790

Update pages/Camera.py

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