websocket url conversion fix (#8)
Browse files- adding conversion to the socket url to run in localhost (6024ae64bef7caf5ec656937eab62d9f19410f41)
Co-authored-by: Dmitri Moscoglo <[email protected]>
src/frontend/gradio/app.py
CHANGED
|
@@ -71,9 +71,14 @@ def get_proxy_url(for_client: bool = False) -> str:
|
|
| 71 |
proxy_url = proxy_url.replace("websocket_proxy", "localhost")
|
| 72 |
return proxy_url
|
| 73 |
|
| 74 |
-
def get_proxy_base_url() -> str:
|
| 75 |
-
"""Get HTTP base URL for proxy API calls.
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
return proxy_url.replace("ws://", "http://").replace("wss://", "https://").replace("/ws/realtime", "")
|
| 78 |
|
| 79 |
def authenticate_voice_screening(email: str, auth_code: str) -> Tuple[str, Optional[str], Optional[str]]:
|
|
@@ -81,7 +86,9 @@ def authenticate_voice_screening(email: str, auth_code: str) -> Tuple[str, Optio
|
|
| 81 |
if not email or not auth_code:
|
| 82 |
return "β Please enter both email and authentication code.", None, None
|
| 83 |
try:
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
response = requests.post(
|
| 86 |
f"{proxy_base}/auth/verify",
|
| 87 |
json={"email": email, "code": auth_code},
|
|
@@ -95,6 +102,9 @@ def authenticate_voice_screening(email: str, auth_code: str) -> Tuple[str, Optio
|
|
| 95 |
else:
|
| 96 |
error_data = response.json() if response.content else {}
|
| 97 |
return f"β Authentication failed: {error_data.get('detail', response.text)}", None, None
|
|
|
|
|
|
|
|
|
|
| 98 |
except Exception as e:
|
| 99 |
return f"β Error connecting to proxy: {str(e)}", None, None
|
| 100 |
|
|
|
|
| 71 |
proxy_url = proxy_url.replace("websocket_proxy", "localhost")
|
| 72 |
return proxy_url
|
| 73 |
|
| 74 |
+
def get_proxy_base_url(for_client: bool = True) -> str:
|
| 75 |
+
"""Get HTTP base URL for proxy API calls.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
for_client: If True, returns URL accessible from browser (localhost).
|
| 79 |
+
If False, returns internal Docker URL (websocket_proxy).
|
| 80 |
+
"""
|
| 81 |
+
proxy_url = get_proxy_url(for_client=for_client)
|
| 82 |
return proxy_url.replace("ws://", "http://").replace("wss://", "https://").replace("/ws/realtime", "")
|
| 83 |
|
| 84 |
def authenticate_voice_screening(email: str, auth_code: str) -> Tuple[str, Optional[str], Optional[str]]:
|
|
|
|
| 86 |
if not email or not auth_code:
|
| 87 |
return "β Please enter both email and authentication code.", None, None
|
| 88 |
try:
|
| 89 |
+
# Use for_client=True since Gradio app may run locally and needs to connect to localhost:8000
|
| 90 |
+
# If running in Docker, the environment variable should be set to use internal URL
|
| 91 |
+
proxy_base = get_proxy_base_url(for_client=True)
|
| 92 |
response = requests.post(
|
| 93 |
f"{proxy_base}/auth/verify",
|
| 94 |
json={"email": email, "code": auth_code},
|
|
|
|
| 102 |
else:
|
| 103 |
error_data = response.json() if response.content else {}
|
| 104 |
return f"β Authentication failed: {error_data.get('detail', response.text)}", None, None
|
| 105 |
+
except requests.exceptions.ConnectionError as e:
|
| 106 |
+
proxy_base = get_proxy_base_url(for_client=True)
|
| 107 |
+
return f"β Error connecting to proxy at {proxy_base}. Make sure the websocket_proxy service is running on port 8000.\n\nIf using Docker, ensure the service is started: `docker compose -f docker/docker-compose.yml up websocket_proxy`", None, None
|
| 108 |
except Exception as e:
|
| 109 |
return f"β Error connecting to proxy: {str(e)}", None, None
|
| 110 |
|
src/frontend/streamlit/voice_screening_ui/app.py
CHANGED
|
@@ -46,11 +46,20 @@ def get_proxy_url(for_client=False):
|
|
| 46 |
|
| 47 |
return proxy_url
|
| 48 |
|
| 49 |
-
def get_proxy_base_url():
|
| 50 |
-
"""Get HTTP base URL for proxy API calls
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
def get_backend_url():
|
| 56 |
"""Get backend API URL from environment or default."""
|
|
@@ -98,9 +107,15 @@ if not st.session_state.session_token:
|
|
| 98 |
if verify_submitted:
|
| 99 |
if user_email and auth_code:
|
| 100 |
try:
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
response = requests.post(
|
| 103 |
-
|
| 104 |
json={"email": user_email, "code": auth_code},
|
| 105 |
timeout=5
|
| 106 |
)
|
|
@@ -265,7 +280,11 @@ if st.session_state.is_interview_active:
|
|
| 265 |
# Proxy health check
|
| 266 |
if HAS_REQUESTS:
|
| 267 |
try:
|
| 268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
health_url = f"{proxy_base}/health"
|
| 270 |
response = requests.get(health_url, timeout=2)
|
| 271 |
if response.status_code == 200:
|
|
|
|
| 46 |
|
| 47 |
return proxy_url
|
| 48 |
|
| 49 |
+
def get_proxy_base_url(for_client: bool = False):
|
| 50 |
+
"""Get HTTP base URL for proxy API calls.
|
| 51 |
+
|
| 52 |
+
Args:
|
| 53 |
+
for_client: If True, returns URL accessible from browser (localhost).
|
| 54 |
+
If False, returns internal Docker URL (websocket_proxy).
|
| 55 |
+
"""
|
| 56 |
+
proxy_url = get_proxy_url(for_client=for_client)
|
| 57 |
+
# Convert WebSocket URL to HTTP URL
|
| 58 |
+
base_url = proxy_url.replace("ws://", "http://").replace("wss://", "https://").replace("/ws/realtime", "")
|
| 59 |
+
# Ensure we have a protocol
|
| 60 |
+
if not base_url.startswith(("http://", "https://")):
|
| 61 |
+
base_url = f"http://{base_url}"
|
| 62 |
+
return base_url
|
| 63 |
|
| 64 |
def get_backend_url():
|
| 65 |
"""Get backend API URL from environment or default."""
|
|
|
|
| 107 |
if verify_submitted:
|
| 108 |
if user_email and auth_code:
|
| 109 |
try:
|
| 110 |
+
# Use for_client=True to get localhost URL when running outside Docker
|
| 111 |
+
# The Streamlit app might be accessed from browser, so use client-accessible URL
|
| 112 |
+
proxy_base = get_proxy_base_url(for_client=True)
|
| 113 |
+
# Ensure URL has protocol
|
| 114 |
+
if not proxy_base.startswith(("http://", "https://")):
|
| 115 |
+
proxy_base = f"http://{proxy_base}"
|
| 116 |
+
auth_url = f"{proxy_base}/auth/verify"
|
| 117 |
response = requests.post(
|
| 118 |
+
auth_url,
|
| 119 |
json={"email": user_email, "code": auth_code},
|
| 120 |
timeout=5
|
| 121 |
)
|
|
|
|
| 280 |
# Proxy health check
|
| 281 |
if HAS_REQUESTS:
|
| 282 |
try:
|
| 283 |
+
# Use for_client=True to get localhost URL when running outside Docker
|
| 284 |
+
proxy_base = get_proxy_base_url(for_client=True)
|
| 285 |
+
# Ensure URL has protocol
|
| 286 |
+
if not proxy_base.startswith(("http://", "https://")):
|
| 287 |
+
proxy_base = f"http://{proxy_base}"
|
| 288 |
health_url = f"{proxy_base}/health"
|
| 289 |
response = requests.get(health_url, timeout=2)
|
| 290 |
if response.status_code == 200:
|