Update Dockerfile
Browse files- Dockerfile +51 -49
Dockerfile
CHANGED
|
@@ -1,56 +1,58 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
-
# Install dependencies
|
| 4 |
RUN pip install --no-cache-dir fastapi uvicorn
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
RUN
|
| 8 |
-
from fastapi
|
| 9 |
-
import
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
<html>
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
<
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
<
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
<
|
| 35 |
-
<div
|
| 36 |
-
|
| 37 |
-
<
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
| 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
|