Spaces:
Running
Running
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 # Add this line to import datetime module | |
app = Flask(__name__) | |
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}) | |
def ping(): | |
# Ping an external service | |
try: | |
response = requests.get("https://example.com") # Change this to your desired external service | |
response.raise_for_status() | |
return jsonify({"ping": "success"}) | |
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) | |