froth61 commited on
Commit
f00d49e
·
verified ·
1 Parent(s): 7b4e4e5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +51 -49
Dockerfile CHANGED
@@ -1,56 +1,58 @@
1
  FROM python:3.9-slim
2
 
3
- # Install dependencies directly
4
  RUN pip install --no-cache-dir fastapi uvicorn
5
 
6
- # Write the Python application to a file using a shell command
7
- RUN printf 'from fastapi import FastAPI\n\
8
- from fastapi.responses import HTMLResponse\n\
9
- import time\n\
10
- \n\
11
- app = FastAPI()\n\
12
- \n\
13
- @app.get("/ping")\n\
14
- async def ping():\n\
15
- return {"status": "pong"}\n\
16
- \n\
17
- @app.get("/", response_class=HTMLResponse)\n\
18
- async def index():\n\
19
- return """\n\
20
- <!DOCTYPE html>\n\
21
- <html>\n\
22
- <head>\n\
23
- <title>HF Space Ping</title>\n\
24
- <style>\n\
25
- body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #f4f4f9; }\n\
26
- .card { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; }\n\
27
- #ping-value { font-size: 3rem; font-weight: bold; color: #4a90e2; }\n\
28
- .unit { font-size: 1.2rem; color: #666; }\n\
29
- </style>\n\
30
- </head>\n\
31
- <body>\n\
32
- <div class="card">\n\
33
- <h2>Your Latency to Space</h2>\n\
34
- <div id="ping-value">0</div>\n\
35
- <div class="unit">ms</div>\n\
36
- </div>\n\
37
- <script>\n\
38
- async function measurePing() {\n\
39
- const start = performance.now();\n\
40
- try {\n\
41
- await fetch(\'/ping\');\n\
42
- const end = performance.now();\n\
43
- document.getElementById(\'ping-value\').innerText = Math.round(end - start);\n\
44
- } catch (e) {\n\
45
- document.getElementById(\'ping-value\').innerText = \'Error\';\n\
46
- }\n\
47
- }\n\
48
- setInterval(measurePing, 1000);\n\
49
- measurePing();\n\
50
- </script>\n\
51
- </body>\n\
52
- </html>\n\
53
- """' > app.py
 
 
54
 
55
  # Hugging Face Spaces use port 7860
56
  EXPOSE 7860
 
1
  FROM python:3.9-slim
2
 
3
+ # Install dependencies
4
  RUN pip install --no-cache-dir fastapi uvicorn
5
 
6
+ # Create the app.py file using a Heredoc to avoid shell syntax errors
7
+ RUN cat <<EOF > app.py
8
+ from fastapi import FastAPI
9
+ from fastapi.responses import HTMLResponse
10
+ import time
11
+
12
+ app = FastAPI()
13
+
14
+ @app.get("/ping")
15
+ async def ping():
16
+ return {"status": "pong"}
17
+
18
+ @app.get("/", response_class=HTMLResponse)
19
+ async def index():
20
+ return """
21
+ <!DOCTYPE html>
22
+ <html>
23
+ <head>
24
+ <title>HF Space Ping</title>
25
+ <style>
26
+ body { font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: #f4f4f9; }
27
+ .card { background: white; padding: 2rem; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; }
28
+ #ping-value { font-size: 3rem; font-weight: bold; color: #4a90e2; }
29
+ .unit { font-size: 1.2rem; color: #666; }
30
+ </style>
31
+ </head>
32
+ <body>
33
+ <div class="card">
34
+ <h2>Your Latency to Space</h2>
35
+ <div id="ping-value">0</div>
36
+ <div class="unit">ms</div>
37
+ </div>
38
+ <script>
39
+ async function measurePing() {
40
+ const start = performance.now();
41
+ try {
42
+ await fetch('/ping');
43
+ const end = performance.now();
44
+ document.getElementById('ping-value').innerText = Math.round(end - start);
45
+ } catch (e) {
46
+ document.getElementById('ping-value').innerText = 'Error';
47
+ }
48
+ }
49
+ setInterval(measurePing, 1000);
50
+ measurePing();
51
+ </script>
52
+ </body>
53
+ </html>
54
+ """
55
+ EOF
56
 
57
  # Hugging Face Spaces use port 7860
58
  EXPOSE 7860