Spaces:
Sleeping
Sleeping
File size: 1,283 Bytes
69c20e8 |
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 37 38 39 40 41 42 43 44 45 46 47 48 |
import subprocess
import time
import webbrowser
import os
import urllib.request
import sys
def is_server_ready(url):
try:
with urllib.request.urlopen(url) as response:
return response.getcode() == 200
except Exception:
return False
def main():
print("π Starting Engine...")
# Definition of the server command
# Using sys.executable to ensure we use the same python interpreter
server_command = [sys.executable, "-m", "uvicorn", "main:app", "--reload"]
# Start the server as a subprocess
process = subprocess.Popen(server_command, cwd=os.getcwd())
server_url = "http://localhost:8000"
# Poll for server availability
try:
while not is_server_ready(server_url):
time.sleep(1)
print("β
Dashboard Launched")
# Open the dashboard in the default web browser
dashboard_path = os.path.abspath("dashboard.html")
webbrowser.open(f"file:///{dashboard_path}")
# Keep the script running to maintain the server process
process.wait()
except KeyboardInterrupt:
print("\nπ Shutting down...")
process.terminate()
process.wait()
if __name__ == "__main__":
main()
|