Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI, Response
|
| 2 |
-
from fastapi.responses import HTMLResponse
|
| 3 |
-
import time
|
| 4 |
-
import uvicorn
|
| 5 |
-
import os
|
| 6 |
-
import psutil
|
| 7 |
-
|
| 8 |
-
app = FastAPI()
|
| 9 |
-
start_time = time.time()
|
| 10 |
-
|
| 11 |
-
def get_cpu_model():
|
| 12 |
-
try:
|
| 13 |
-
with open("/proc/cpuinfo", "r") as f:
|
| 14 |
-
for line in f:
|
| 15 |
-
if "model name" in line:
|
| 16 |
-
return line.split(":")[1].strip()
|
| 17 |
-
except:
|
| 18 |
-
pass
|
| 19 |
-
return "Virtual vCPU"
|
| 20 |
-
|
| 21 |
-
@app.get("/", response_class=HTMLResponse)
|
| 22 |
-
def read_root():
|
| 23 |
-
# Просто читаем готовый HTML-файл из корня проекта
|
| 24 |
-
if os.path.exists("index.html"):
|
| 25 |
-
with open("index.html", "r", encoding="utf-8") as f:
|
| 26 |
-
return HTMLResponse(content=f.read(), status_code=200)
|
| 27 |
-
return HTMLResponse(content="<h1>Error: index.html not found</h1>", status_code=404)
|
| 28 |
-
|
| 29 |
-
@app.get("/api/real_specs")
|
| 30 |
-
def get_real_specs():
|
| 31 |
-
uptime_seconds = int(time.time() - start_time)
|
| 32 |
-
hours, remainder = divmod(uptime_seconds, 3600)
|
| 33 |
-
minutes, seconds = divmod(remainder, 60)
|
| 34 |
-
uptime_string = f"{hours:02d}h {minutes:02d}m {seconds:02d}s"
|
| 35 |
-
|
| 36 |
-
ram = psutil.virtual_memory()
|
| 37 |
-
ram_total_gb = round(ram.total / (1024**3), 1)
|
| 38 |
-
ram_used_gb = round(ram.used / (1024**3), 1)
|
| 39 |
-
ram_percent = ram.percent
|
| 40 |
-
|
| 41 |
-
disk = psutil.disk_usage('/')
|
| 42 |
-
disk_total_gb = round(disk.total / (1024**3), 1)
|
| 43 |
-
disk_free_gb = round(disk.free / (1024**3), 1)
|
| 44 |
-
disk_used_gb = round(disk.used / (1024**3), 1)
|
| 45 |
-
|
| 46 |
-
cpu_usage = psutil.cpu_percent(interval=None)
|
| 47 |
-
cpu_cores = os.cpu_count()
|
| 48 |
-
cpu_model = get_cpu_model()
|
| 49 |
-
|
| 50 |
-
return {
|
| 51 |
-
"uptime": uptime_string,
|
| 52 |
-
"cpu_model": cpu_model,
|
| 53 |
-
"cpu_cores": cpu_cores,
|
| 54 |
-
"cpu_usage": cpu_usage,
|
| 55 |
-
"ram_total": ram_total_gb,
|
| 56 |
-
"ram_used": ram_used_gb,
|
| 57 |
-
"ram_percent": ram_percent,
|
| 58 |
-
"disk_total": disk_total_gb,
|
| 59 |
-
"disk_free": disk_free_gb,
|
| 60 |
-
"disk_used": disk_used_gb
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
@app.api_route("/my_secret_ping_9912", methods=["GET", "HEAD", "POST"])
|
| 64 |
-
def ping():
|
| 65 |
-
return Response(content="Status: OK", media_type="text/plain")
|
| 66 |
-
|
| 67 |
-
if __name__ == "__main__":
|
| 68 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|