Spaces:
Sleeping
Sleeping
Raymond Weitekamp
commited on
Commit
·
5d6474b
1
Parent(s):
67e0e6d
Fix viewer proxy configuration for Hugging Face Spaces
Browse files- Dockerfile +24 -4
- cadviewer.py +3 -3
Dockerfile
CHANGED
|
@@ -63,29 +63,49 @@ events {\n\
|
|
| 63 |
}\n\
|
| 64 |
http {\n\
|
| 65 |
access_log /dev/stdout;\n\
|
|
|
|
|
|
|
| 66 |
upstream nicegui {\n\
|
| 67 |
server 127.0.0.1:7861;\n\
|
| 68 |
}\n\
|
|
|
|
| 69 |
upstream viewer {\n\
|
| 70 |
server 127.0.0.1:3939;\n\
|
| 71 |
}\n\
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
server {\n\
|
| 73 |
listen 7860;\n\
|
| 74 |
server_name localhost;\n\
|
|
|
|
|
|
|
| 75 |
location / {\n\
|
| 76 |
proxy_pass http://nicegui;\n\
|
| 77 |
proxy_http_version 1.1;\n\
|
| 78 |
proxy_set_header Upgrade $http_upgrade;\n\
|
| 79 |
-
proxy_set_header Connection
|
| 80 |
proxy_set_header Host $host;\n\
|
|
|
|
|
|
|
|
|
|
| 81 |
}\n\
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
proxy_http_version 1.1;\n\
|
| 85 |
proxy_set_header Upgrade $http_upgrade;\n\
|
| 86 |
-
proxy_set_header Connection
|
| 87 |
proxy_set_header Host $host;\n\
|
|
|
|
|
|
|
|
|
|
| 88 |
proxy_read_timeout 86400;\n\
|
|
|
|
| 89 |
}\n\
|
| 90 |
}\n\
|
| 91 |
}' > /etc/nginx/nginx.conf && \
|
|
|
|
| 63 |
}\n\
|
| 64 |
http {\n\
|
| 65 |
access_log /dev/stdout;\n\
|
| 66 |
+
client_max_body_size 0;\n\
|
| 67 |
+
\n\
|
| 68 |
upstream nicegui {\n\
|
| 69 |
server 127.0.0.1:7861;\n\
|
| 70 |
}\n\
|
| 71 |
+
\n\
|
| 72 |
upstream viewer {\n\
|
| 73 |
server 127.0.0.1:3939;\n\
|
| 74 |
}\n\
|
| 75 |
+
\n\
|
| 76 |
+
map $http_upgrade $connection_upgrade {\n\
|
| 77 |
+
default upgrade;\n\
|
| 78 |
+
"" close;\n\
|
| 79 |
+
}\n\
|
| 80 |
+
\n\
|
| 81 |
server {\n\
|
| 82 |
listen 7860;\n\
|
| 83 |
server_name localhost;\n\
|
| 84 |
+
\n\
|
| 85 |
+
# Main app (NiceGUI)\n\
|
| 86 |
location / {\n\
|
| 87 |
proxy_pass http://nicegui;\n\
|
| 88 |
proxy_http_version 1.1;\n\
|
| 89 |
proxy_set_header Upgrade $http_upgrade;\n\
|
| 90 |
+
proxy_set_header Connection $connection_upgrade;\n\
|
| 91 |
proxy_set_header Host $host;\n\
|
| 92 |
+
proxy_set_header X-Real-IP $remote_addr;\n\
|
| 93 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
| 94 |
+
proxy_set_header X-Forwarded-Proto $scheme;\n\
|
| 95 |
}\n\
|
| 96 |
+
\n\
|
| 97 |
+
# Viewer route\n\
|
| 98 |
+
location /viewer/ {\n\
|
| 99 |
+
proxy_pass http://viewer/viewer/;\n\
|
| 100 |
proxy_http_version 1.1;\n\
|
| 101 |
proxy_set_header Upgrade $http_upgrade;\n\
|
| 102 |
+
proxy_set_header Connection $connection_upgrade;\n\
|
| 103 |
proxy_set_header Host $host;\n\
|
| 104 |
+
proxy_set_header X-Real-IP $remote_addr;\n\
|
| 105 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\
|
| 106 |
+
proxy_set_header X-Forwarded-Proto $scheme;\n\
|
| 107 |
proxy_read_timeout 86400;\n\
|
| 108 |
+
proxy_buffering off;\n\
|
| 109 |
}\n\
|
| 110 |
}\n\
|
| 111 |
}' > /etc/nginx/nginx.conf && \
|
cadviewer.py
CHANGED
|
@@ -101,8 +101,8 @@ def check_viewer_ready():
|
|
| 101 |
"""Check if the viewer is ready by attempting a test connection"""
|
| 102 |
try:
|
| 103 |
import requests
|
| 104 |
-
# Check
|
| 105 |
-
response = requests.get('http://localhost:
|
| 106 |
return response.status_code == 200
|
| 107 |
except Exception as e:
|
| 108 |
logger.error(f"Error checking viewer: {str(e)}")
|
|
@@ -199,7 +199,7 @@ with ui.splitter().classes(
|
|
| 199 |
logger.info(f"Space URL: {space_url}")
|
| 200 |
|
| 201 |
# Construct the viewer URL - use relative path for both local and Space environments
|
| 202 |
-
viewer_url = "/
|
| 203 |
logger.info(f"Using viewer URL: {viewer_url}")
|
| 204 |
|
| 205 |
ocpcv = (
|
|
|
|
| 101 |
"""Check if the viewer is ready by attempting a test connection"""
|
| 102 |
try:
|
| 103 |
import requests
|
| 104 |
+
# Check the viewer through Nginx proxy
|
| 105 |
+
response = requests.get('http://localhost:7860/viewer/')
|
| 106 |
return response.status_code == 200
|
| 107 |
except Exception as e:
|
| 108 |
logger.error(f"Error checking viewer: {str(e)}")
|
|
|
|
| 199 |
logger.info(f"Space URL: {space_url}")
|
| 200 |
|
| 201 |
# Construct the viewer URL - use relative path for both local and Space environments
|
| 202 |
+
viewer_url = "/viewer/" # Changed to match Nginx configuration
|
| 203 |
logger.info(f"Using viewer URL: {viewer_url}")
|
| 204 |
|
| 205 |
ocpcv = (
|