Spaces:
Running
Running
feat: improve Docker deployment with analytics disable and nginx optimization
Browse files- Dockerfile +10 -3
- app.py +6 -1
- manifest.json +16 -0
- nginx.conf +39 -64
- start.sh +1 -8
Dockerfile
CHANGED
@@ -12,10 +12,10 @@ WORKDIR /app
|
|
12 |
COPY ./requirements.txt requirements.txt
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
15 |
-
# Copy nginx configuration
|
16 |
-
COPY nginx.conf /
|
17 |
|
18 |
-
# Create
|
19 |
RUN mkdir -p /var/run/nginx /var/log/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi \
|
20 |
/var/lib/nginx/proxy /var/lib/nginx/scgi /var/lib/nginx/uwsgi && \
|
21 |
chown -R user:user /var/run/nginx /var/log/nginx /var/lib/nginx
|
@@ -27,5 +27,12 @@ RUN chmod +x /app/start.sh
|
|
27 |
# Switch to user for execution
|
28 |
USER user
|
29 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
CMD ["/app/start.sh"]
|
|
|
12 |
COPY ./requirements.txt requirements.txt
|
13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
|
15 |
+
# Copy nginx configuration
|
16 |
+
COPY nginx.conf /app/nginx.conf
|
17 |
|
18 |
+
# Create nginx directories and set permissions for user
|
19 |
RUN mkdir -p /var/run/nginx /var/log/nginx /var/lib/nginx/body /var/lib/nginx/fastcgi \
|
20 |
/var/lib/nginx/proxy /var/lib/nginx/scgi /var/lib/nginx/uwsgi && \
|
21 |
chown -R user:user /var/run/nginx /var/log/nginx /var/lib/nginx
|
|
|
27 |
# Switch to user for execution
|
28 |
USER user
|
29 |
ENV PATH="/home/user/.local/bin:$PATH"
|
30 |
+
ENV GRADIO_ANALYTICS_ENABLED=False
|
31 |
+
ENV GRADIO_ANALYTICS_ENABLED=false
|
32 |
+
ENV HF_HUB_DISABLE_TELEMETRY=1
|
33 |
+
ENV GRADIO_TELEMETRY_ENABLED=False
|
34 |
+
ENV MPLCONFIGDIR=/tmp/matplotlib
|
35 |
+
|
36 |
+
EXPOSE 7860
|
37 |
|
38 |
CMD ["/app/start.sh"]
|
app.py
CHANGED
@@ -563,7 +563,11 @@ class GradioUI:
|
|
563 |
)
|
564 |
|
565 |
def launch(self, share: bool = True, **kwargs):
|
566 |
-
self.create_app().launch(
|
|
|
|
|
|
|
|
|
567 |
|
568 |
def create_app(self):
|
569 |
import gradio as gr
|
@@ -573,6 +577,7 @@ class GradioUI:
|
|
573 |
theme=gr.themes.Soft(),
|
574 |
fill_height=True,
|
575 |
fill_width=True,
|
|
|
576 |
) as demo:
|
577 |
gr.Markdown("# 💗Likable")
|
578 |
|
|
|
563 |
)
|
564 |
|
565 |
def launch(self, share: bool = True, **kwargs):
|
566 |
+
self.create_app().launch(
|
567 |
+
debug=True,
|
568 |
+
share=share,
|
569 |
+
**kwargs,
|
570 |
+
)
|
571 |
|
572 |
def create_app(self):
|
573 |
import gradio as gr
|
|
|
577 |
theme=gr.themes.Soft(),
|
578 |
fill_height=True,
|
579 |
fill_width=True,
|
580 |
+
analytics_enabled=False,
|
581 |
) as demo:
|
582 |
gr.Markdown("# 💗Likable")
|
583 |
|
manifest.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "💗Likable",
|
3 |
+
"short_name": "Likable",
|
4 |
+
"description": "It's almost lovable...",
|
5 |
+
"start_url": "/",
|
6 |
+
"display": "standalone",
|
7 |
+
"theme_color": "#000000",
|
8 |
+
"background_color": "#ffffff",
|
9 |
+
"icons": [
|
10 |
+
{
|
11 |
+
"src": "/favicon.ico",
|
12 |
+
"sizes": "any",
|
13 |
+
"type": "image/x-icon"
|
14 |
+
}
|
15 |
+
]
|
16 |
+
}
|
nginx.conf
CHANGED
@@ -1,93 +1,68 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
pid /
|
4 |
-
error_log /
|
5 |
|
6 |
events {
|
7 |
-
worker_connections
|
8 |
}
|
9 |
|
10 |
http {
|
11 |
include /etc/nginx/mime.types;
|
12 |
default_type application/octet-stream;
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
proxy_temp_path /var/lib/nginx/proxy;
|
17 |
-
fastcgi_temp_path /var/lib/nginx/fastcgi;
|
18 |
-
uwsgi_temp_path /var/lib/nginx/uwsgi;
|
19 |
-
scgi_temp_path /var/lib/nginx/scgi;
|
20 |
-
|
21 |
-
access_log /var/log/nginx/access.log;
|
22 |
-
|
23 |
-
# Upstream configuration for better load balancing and failover
|
24 |
-
upstream preview_backend {
|
25 |
-
server localhost:7861 max_fails=1 fail_timeout=5s;
|
26 |
-
keepalive 32;
|
27 |
}
|
28 |
|
29 |
-
upstream
|
30 |
-
server
|
31 |
-
keepalive 32;
|
32 |
}
|
33 |
|
34 |
server {
|
35 |
listen 7860 default_server;
|
36 |
-
listen [::]:7860 default_server;
|
37 |
-
|
38 |
server_name _;
|
39 |
|
40 |
-
#
|
41 |
-
location / {
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
proxy_set_header Host $host;
|
47 |
-
proxy_set_header X-Real-IP $remote_addr;
|
48 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
49 |
-
proxy_set_header X-Forwarded-Host $host;
|
50 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
51 |
-
proxy_cache_bypass $http_upgrade;
|
52 |
-
proxy_read_timeout 86400;
|
53 |
-
proxy_connect_timeout 10s;
|
54 |
-
proxy_send_timeout 10s;
|
55 |
-
proxy_redirect off;
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
proxy_busy_buffers_size 8k;
|
62 |
}
|
63 |
|
64 |
-
# Preview apps - route to internal port 7861
|
65 |
location /preview/ {
|
66 |
-
# Remove /preview prefix and pass to the sandbox app
|
67 |
rewrite /preview/(.*) /$1 break;
|
68 |
proxy_pass http://preview_backend;
|
|
|
|
|
69 |
proxy_http_version 1.1;
|
70 |
proxy_set_header Upgrade $http_upgrade;
|
71 |
-
proxy_set_header Connection
|
72 |
-
proxy_set_header Host $
|
73 |
-
proxy_set_header X-
|
74 |
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
75 |
-
proxy_set_header X-Forwarded-Host $host;
|
76 |
proxy_set_header X-Forwarded-Proto $scheme;
|
77 |
-
|
78 |
-
proxy_read_timeout 86400;
|
79 |
-
proxy_connect_timeout 10s;
|
80 |
-
proxy_send_timeout 10s;
|
81 |
-
proxy_redirect off;
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
}
|
92 |
}
|
93 |
}
|
|
|
1 |
+
worker_processes 1;
|
2 |
+
daemon off;
|
3 |
+
pid /tmp/nginx.pid;
|
4 |
+
error_log /tmp/error.log;
|
5 |
|
6 |
events {
|
7 |
+
worker_connections 1024;
|
8 |
}
|
9 |
|
10 |
http {
|
11 |
include /etc/nginx/mime.types;
|
12 |
default_type application/octet-stream;
|
13 |
+
access_log /tmp/access.log;
|
14 |
+
sendfile on;
|
15 |
+
keepalive_timeout 65;
|
16 |
+
client_max_body_size 100M;
|
17 |
|
18 |
+
upstream main_backend {
|
19 |
+
server 127.0.0.1:7862;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
21 |
|
22 |
+
upstream preview_backend {
|
23 |
+
server 127.0.0.1:7861;
|
|
|
24 |
}
|
25 |
|
26 |
server {
|
27 |
listen 7860 default_server;
|
|
|
|
|
28 |
server_name _;
|
29 |
|
30 |
+
# Serve manifest.json directly
|
31 |
+
location = /manifest.json {
|
32 |
+
root /app;
|
33 |
+
add_header Content-Type "application/manifest+json";
|
34 |
+
try_files $uri =404;
|
35 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
# Handle missing fallback font files gracefully
|
38 |
+
location ~ ^/static/fonts/(ui-sans-serif|system-ui)/ {
|
39 |
+
access_log off;
|
40 |
+
return 204;
|
|
|
41 |
}
|
42 |
|
|
|
43 |
location /preview/ {
|
|
|
44 |
rewrite /preview/(.*) /$1 break;
|
45 |
proxy_pass http://preview_backend;
|
46 |
+
proxy_buffering off;
|
47 |
+
proxy_redirect off;
|
48 |
proxy_http_version 1.1;
|
49 |
proxy_set_header Upgrade $http_upgrade;
|
50 |
+
proxy_set_header Connection "upgrade";
|
51 |
+
proxy_set_header Host $http_host;
|
52 |
+
proxy_set_header X-Forwarded-Host $http_host;
|
|
|
|
|
53 |
proxy_set_header X-Forwarded-Proto $scheme;
|
54 |
+
}
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
location / {
|
57 |
+
proxy_pass http://main_backend;
|
58 |
+
proxy_buffering off;
|
59 |
+
proxy_redirect off;
|
60 |
+
proxy_http_version 1.1;
|
61 |
+
proxy_set_header Upgrade $http_upgrade;
|
62 |
+
proxy_set_header Connection "upgrade";
|
63 |
+
proxy_set_header Host $http_host;
|
64 |
+
proxy_set_header X-Forwarded-Host $http_host;
|
65 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
66 |
}
|
67 |
}
|
68 |
}
|
start.sh
CHANGED
@@ -1,15 +1,8 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
-
# Create necessary directories
|
4 |
-
mkdir -p /var/run/nginx /var/lib/nginx/body /var/lib/nginx/proxy /var/lib/nginx/fastcgi /var/lib/nginx/uwsgi /var/lib/nginx/scgi /var/log/nginx
|
5 |
-
|
6 |
-
# Set proper permissions
|
7 |
-
chmod 755 /var/run/nginx /var/lib/nginx/* /var/log/nginx
|
8 |
-
|
9 |
# Start nginx with our configuration
|
10 |
echo "Starting nginx..."
|
11 |
-
nginx -c /app/nginx.conf
|
12 |
-
sleep 2
|
13 |
|
14 |
# Start the main Gradio app
|
15 |
echo "Starting Gradio app on port 7862..."
|
|
|
1 |
#!/bin/bash
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
# Start nginx with our configuration
|
4 |
echo "Starting nginx..."
|
5 |
+
nginx -c /app/nginx.conf &
|
|
|
6 |
|
7 |
# Start the main Gradio app
|
8 |
echo "Starting Gradio app on port 7862..."
|