File size: 1,227 Bytes
53f7a0c
4a672f4
0006475
ae6d72e
 
6a97cfb
 
cf50e46
4a672f4
62e7ddb
4a672f4
6a97cfb
 
 
 
 
 
 
 
 
 
cf50e46
6a97cfb
cf50e46
 
6a97cfb
cf50e46
 
 
6a97cfb
 
 
 
f984e57
6a97cfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask, request, jsonify, send_from_directory
import os
import requests
from PIL import Image
from io import BytesIO
import psutil
import time
import datetime  

app = Flask(__name__)

@app.route("/uptime")
def uptime():
    # Get system uptime using psutil
    uptime_seconds = int(time.time() - psutil.boot_time())
    uptime_string = str(datetime.timedelta(seconds=uptime_seconds))
    return jsonify({"uptime": uptime_string})


@app.route("/ping")
def ping():
    # Ping an external service and measure the response time
    try:
        start_time = time.time()  # Start time before making the request
        response = requests.get("https://kastg-cdn.hf.space/")  # Change this to your desired external service
        response.raise_for_status()
        end_time = time.time()  # End time after receiving the response
        elapsed_time_ms = round((end_time - start_time) * 1000, 2)  # Calculate elapsed time in milliseconds
        return jsonify({"ping": "success", "response_time_ms": elapsed_time_ms})
    except requests.exceptions.RequestException as e:
        return jsonify({"ping": f"failed: {str(e)}"}), 500


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860, debug=True)