Commit
·
697963f
1
Parent(s):
7f1ff29
Add proper error checking of ICE servers from Twilio
Browse files- src/streamlit_app.py +14 -8
src/streamlit_app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import sys
|
3 |
import asyncio
|
4 |
import tempfile
|
|
|
5 |
|
6 |
from dotenv import load_dotenv
|
7 |
from twilio.rest import Client
|
@@ -9,7 +10,6 @@ from twilio.rest import Client
|
|
9 |
load_dotenv()
|
10 |
account_sid = os.getenv("TWILIO_SID")
|
11 |
auth_token = os.getenv("TWILIO_TOKEN")
|
12 |
-
twilio_client = Client(account_sid, auth_token)
|
13 |
|
14 |
os.environ["HOME"] = "/tmp"
|
15 |
os.environ["STREAMLIT_HOME"] = "/tmp"
|
@@ -29,6 +29,19 @@ from PIL import Image
|
|
29 |
|
30 |
import streamlit as st
|
31 |
from streamlit_webrtc import VideoProcessorBase, webrtc_streamer, RTCConfiguration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
import matplotlib.pyplot as plt
|
34 |
from huggingface_hub import hf_hub_download
|
@@ -47,13 +60,6 @@ if gpus:
|
|
47 |
from nets import get_model_from_name
|
48 |
from utils.utils import (cvtColor, get_classes, letterbox_image, preprocess_input)
|
49 |
|
50 |
-
try:
|
51 |
-
token = twilio_client.tokens.create()
|
52 |
-
ICE_SERVERS = token.ice_servers
|
53 |
-
except Exception as e:
|
54 |
-
st.error(f"Failed to get ICE servers from Twilio: {e}")
|
55 |
-
ICE_SERVERS = [{"urls": ["stun:stun.l.google.com:19302"]}]
|
56 |
-
|
57 |
|
58 |
# --- Classification class (merged from classification.py) ---
|
59 |
cache_dir = os.path.join(tempfile.gettempdir(), "hf_cache")
|
|
|
2 |
import sys
|
3 |
import asyncio
|
4 |
import tempfile
|
5 |
+
import traceback
|
6 |
|
7 |
from dotenv import load_dotenv
|
8 |
from twilio.rest import Client
|
|
|
10 |
load_dotenv()
|
11 |
account_sid = os.getenv("TWILIO_SID")
|
12 |
auth_token = os.getenv("TWILIO_TOKEN")
|
|
|
13 |
|
14 |
os.environ["HOME"] = "/tmp"
|
15 |
os.environ["STREAMLIT_HOME"] = "/tmp"
|
|
|
29 |
|
30 |
import streamlit as st
|
31 |
from streamlit_webrtc import VideoProcessorBase, webrtc_streamer, RTCConfiguration
|
32 |
+
if account_sid and auth_token:
|
33 |
+
try:
|
34 |
+
twilio_client = Client(account_sid, auth_token)
|
35 |
+
token = twilio_client.tokens.create()
|
36 |
+
ICE_SERVERS = token.ice_servers
|
37 |
+
st.success("✅ Using Twilio TURN/STUN servers")
|
38 |
+
except Exception as e:
|
39 |
+
ICE_SERVERS = [{"urls": ["stun:stun.l.google.com:19302"]}]
|
40 |
+
st.error(f"❌ Failed to get ICE servers from Twilio: {e}")
|
41 |
+
st.text(traceback.format_exc())
|
42 |
+
else:
|
43 |
+
st.warning("⚠️ Twilio credentials not set. Falling back to STUN-only.")
|
44 |
+
|
45 |
|
46 |
import matplotlib.pyplot as plt
|
47 |
from huggingface_hub import hf_hub_download
|
|
|
60 |
from nets import get_model_from_name
|
61 |
from utils.utils import (cvtColor, get_classes, letterbox_image, preprocess_input)
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# --- Classification class (merged from classification.py) ---
|
65 |
cache_dir = os.path.join(tempfile.gettempdir(), "hf_cache")
|