Spaces:
Running
Running
Kastg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
|
|
5 |
from io import BytesIO
|
6 |
import psutil
|
7 |
import time
|
8 |
-
import datetime
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
@@ -19,11 +19,14 @@ def uptime():
|
|
19 |
|
20 |
@app.route("/ping")
|
21 |
def ping():
|
22 |
-
# Ping an external service
|
23 |
try:
|
24 |
-
|
|
|
25 |
response.raise_for_status()
|
26 |
-
|
|
|
|
|
27 |
except requests.exceptions.RequestException as e:
|
28 |
return jsonify({"ping": f"failed: {str(e)}"}), 500
|
29 |
|
|
|
5 |
from io import BytesIO
|
6 |
import psutil
|
7 |
import time
|
8 |
+
import datetime
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
|
|
19 |
|
20 |
@app.route("/ping")
|
21 |
def ping():
|
22 |
+
# Ping an external service and measure the response time
|
23 |
try:
|
24 |
+
start_time = time.time() # Start time before making the request
|
25 |
+
response = requests.get("https://kastg-cdn.hf.space/") # Change this to your desired external service
|
26 |
response.raise_for_status()
|
27 |
+
end_time = time.time() # End time after receiving the response
|
28 |
+
elapsed_time_ms = round((end_time - start_time) * 1000, 2) # Calculate elapsed time in milliseconds
|
29 |
+
return jsonify({"ping": "success", "response_time_ms": elapsed_time_ms})
|
30 |
except requests.exceptions.RequestException as e:
|
31 |
return jsonify({"ping": f"failed: {str(e)}"}), 500
|
32 |
|