Factor Studios commited on
Commit
400492b
·
verified ·
1 Parent(s): e94c576

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +97 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from fastapi.responses import HTMLResponse
4
+ import shutil
5
+ import uvicorn
6
+
7
+ app = FastAPI(title="Disk Space Monitor", description="A simple API to monitor disk space")
8
+
9
+ # Add CORS middleware
10
+ app.add_middleware(
11
+ CORSMiddleware,
12
+ allow_origins=["*"],
13
+ allow_credentials=True,
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
+ )
17
+
18
+ def get_disk_space():
19
+ """Get disk space information"""
20
+ total, used, free = shutil.disk_usage("/")
21
+ return {
22
+ "total_gb": round(total / (1024**3), 2),
23
+ "used_gb": round(used / (1024**3), 2),
24
+ "free_gb": round(free / (1024**3), 2),
25
+ "used_percentage": round((used / total) * 100, 2)
26
+ }
27
+
28
+ @app.get("/")
29
+ async def root():
30
+ """Root endpoint with HTML interface"""
31
+ disk_info = get_disk_space()
32
+ html_content = f"""
33
+ <!DOCTYPE html>
34
+ <html>
35
+ <head>
36
+ <title>Disk Space Monitor</title>
37
+ <style>
38
+ body {{ font-family: Arial, sans-serif; margin: 40px; background-color: #f5f5f5; }}
39
+ .container {{ max-width: 600px; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }}
40
+ h1 {{ color: #333; text-align: center; }}
41
+ .disk-info {{ background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 20px 0; }}
42
+ .metric {{ display: flex; justify-content: space-between; margin: 10px 0; padding: 10px; background: white; border-radius: 5px; }}
43
+ .metric-label {{ font-weight: bold; color: #555; }}
44
+ .metric-value {{ color: #007bff; font-weight: bold; }}
45
+ .progress-bar {{ width: 100%; height: 20px; background: #e9ecef; border-radius: 10px; overflow: hidden; margin: 10px 0; }}
46
+ .progress-fill {{ height: 100%; background: linear-gradient(90deg, #28a745, #ffc107, #dc3545); transition: width 0.3s ease; }}
47
+ .refresh-btn {{ background: #007bff; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; margin: 10px 0; }}
48
+ .refresh-btn:hover {{ background: #0056b3; }}
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <div class="container">
53
+ <h1>🖥️ Disk Space Monitor</h1>
54
+ <div class="disk-info">
55
+ <div class="metric">
56
+ <span class="metric-label">Total Space:</span>
57
+ <span class="metric-value">{disk_info['total_gb']} GB</span>
58
+ </div>
59
+ <div class="metric">
60
+ <span class="metric-label">Used Space:</span>
61
+ <span class="metric-value">{disk_info['used_gb']} GB</span>
62
+ </div>
63
+ <div class="metric">
64
+ <span class="metric-label">Free Space:</span>
65
+ <span class="metric-value">{disk_info['free_gb']} GB</span>
66
+ </div>
67
+ <div class="metric">
68
+ <span class="metric-label">Usage:</span>
69
+ <span class="metric-value">{disk_info['used_percentage']}%</span>
70
+ </div>
71
+ <div class="progress-bar">
72
+ <div class="progress-fill" style="width: {disk_info['used_percentage']}%"></div>
73
+ </div>
74
+ <button class="refresh-btn" onclick="location.reload()">🔄 Refresh</button>
75
+ </div>
76
+ <p style="text-align: center; color: #666; margin-top: 30px;">
77
+ API Endpoints: <a href="/api/disk-space">/api/disk-space</a> | <a href="/docs">/docs</a>
78
+ </p>
79
+ </div>
80
+ </body>
81
+ </html>
82
+ """
83
+ return HTMLResponse(content=html_content)
84
+
85
+ @app.get("/api/disk-space")
86
+ async def get_disk_space_api():
87
+ """API endpoint to get disk space information in JSON format"""
88
+ return get_disk_space()
89
+
90
+ @app.get("/health")
91
+ async def health_check():
92
+ """Health check endpoint"""
93
+ return {"status": "healthy", "service": "disk-space-monitor"}
94
+
95
+ if __name__ == "__main__":
96
+ uvicorn.run(app, host="0.0.0.0", port=8000)
97
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn