freddyaboulton HF staff commited on
Commit
c990066
·
verified ·
1 Parent(s): 7e1afe1

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +2 -2
  2. index.html +32 -2
app.py CHANGED
@@ -13,7 +13,7 @@ from pydantic import BaseModel, Field
13
  try:
14
  from demo.object_detection.inference import YOLOv10
15
  except (ImportError, ModuleNotFoundError):
16
- from .inference import YOLOv10
17
 
18
 
19
  cur_dir = Path(__file__).parent
@@ -74,7 +74,7 @@ if __name__ == "__main__":
74
  import os
75
 
76
  if (mode := os.getenv("MODE")) == "UI":
77
- stream.ui.launch(server_port=7860, server_name="0.0.0.0")
78
  elif mode == "PHONE":
79
  stream.fastphone(host="0.0.0.0", port=7860)
80
  else:
 
13
  try:
14
  from demo.object_detection.inference import YOLOv10
15
  except (ImportError, ModuleNotFoundError):
16
+ from inference import YOLOv10
17
 
18
 
19
  cur_dir = Path(__file__).parent
 
74
  import os
75
 
76
  if (mode := os.getenv("MODE")) == "UI":
77
+ stream.ui.launch(server_port=7860)
78
  elif mode == "PHONE":
79
  stream.fastphone(host="0.0.0.0", port=7860)
80
  else:
index.html CHANGED
@@ -119,8 +119,6 @@
119
  top: 20px;
120
  left: 50%;
121
  transform: translateX(-50%);
122
- background-color: #f44336;
123
- color: white;
124
  padding: 16px 24px;
125
  border-radius: 4px;
126
  font-size: 14px;
@@ -128,6 +126,16 @@
128
  display: none;
129
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
130
  }
 
 
 
 
 
 
 
 
 
 
131
  </style>
132
  </head>
133
 
@@ -181,6 +189,7 @@
181
  function showError(message) {
182
  const toast = document.getElementById('error-toast');
183
  toast.textContent = message;
 
184
  toast.style.display = 'block';
185
 
186
  // Hide toast after 5 seconds
@@ -193,6 +202,18 @@
193
  const config = __RTC_CONFIGURATION__;
194
  peerConnection = new RTCPeerConnection(config);
195
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  try {
197
  const stream = await navigator.mediaDevices.getUserMedia({
198
  video: true
@@ -263,7 +284,16 @@
263
  // Send initial confidence threshold
264
  updateConfThreshold(confThreshold.value);
265
 
 
 
 
 
 
 
 
 
266
  } catch (err) {
 
267
  console.error('Error setting up WebRTC:', err);
268
  showError('Failed to establish connection. Please try again.');
269
  stop();
 
119
  top: 20px;
120
  left: 50%;
121
  transform: translateX(-50%);
 
 
122
  padding: 16px 24px;
123
  border-radius: 4px;
124
  font-size: 14px;
 
126
  display: none;
127
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
128
  }
129
+
130
+ .toast.error {
131
+ background-color: #f44336;
132
+ color: white;
133
+ }
134
+
135
+ .toast.warning {
136
+ background-color: #ffd700;
137
+ color: black;
138
+ }
139
  </style>
140
  </head>
141
 
 
189
  function showError(message) {
190
  const toast = document.getElementById('error-toast');
191
  toast.textContent = message;
192
+ toast.className = 'toast error';
193
  toast.style.display = 'block';
194
 
195
  // Hide toast after 5 seconds
 
202
  const config = __RTC_CONFIGURATION__;
203
  peerConnection = new RTCPeerConnection(config);
204
 
205
+ const timeoutId = setTimeout(() => {
206
+ const toast = document.getElementById('error-toast');
207
+ toast.textContent = "Connection is taking longer than usual. Are you on a VPN?";
208
+ toast.className = 'toast warning';
209
+ toast.style.display = 'block';
210
+
211
+ // Hide warning after 5 seconds
212
+ setTimeout(() => {
213
+ toast.style.display = 'none';
214
+ }, 5000);
215
+ }, 5000);
216
+
217
  try {
218
  const stream = await navigator.mediaDevices.getUserMedia({
219
  video: true
 
284
  // Send initial confidence threshold
285
  updateConfThreshold(confThreshold.value);
286
 
287
+ peerConnection.addEventListener('connectionstatechange', () => {
288
+ if (peerConnection.connectionState === 'connected') {
289
+ clearTimeout(timeoutId);
290
+ const toast = document.getElementById('error-toast');
291
+ toast.style.display = 'none';
292
+ }
293
+ });
294
+
295
  } catch (err) {
296
+ clearTimeout(timeoutId);
297
  console.error('Error setting up WebRTC:', err);
298
  showError('Failed to establish connection. Please try again.');
299
  stop();