SuperAI_Forecast / backend /launcher.py
Thang6822
Deploy to Hugging Face with LFS
7c78a60
Raw
History Blame
3.44 kB
import sys
import os
import time
import webbrowser
import threading
import uvicorn
import logging
# Set up professional logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(levelname)s | %(message)s",
)
logger = logging.getLogger("super-ai-launcher")
# ASCII Art Header
BANNER = r"""
____ _ _ ____ _____ ____ _ ___ _ _ _ _ _ __ ______ ___ ____
/ ___|| | | | _ \| ____| _ \ / \ |_ _| / \ | \ | | / \ | | \ \ / / ___|_ _/ ___|
\___ \| | | | |_) | _| | |_) | / _ \ | | / _ \ | \| | / _ \ | | \ V /\___ \ | \___ \
___) | |_| | __/| |___| _ < / ___ \ | | / ___ \| |\ |/ ___ \| |___| | ___) | | ___) |
|____/ \___/|_| |_____|_| \_\/_/ \_\___| /_/ \_\_| \_/_/ \_\_____|_| |____/___|____/
══════════════════════════════════════════════════════════════════════════════════════════════
TRADING INTELLIGENT TERMINAL - AI PHΓ‚N TÍCH BIα»‚U ĐỒ NαΊΎN SỐ 1 THαΊΎ GIỚI
══════════════════════════════════════════════════════════════════════════════════════════════
"""
def print_banner():
# Clear console for a clean startup
os.system('cls' if os.name == 'nt' else 'clear')
print("\033[96m" + BANNER + "\033[0m")
print(" [*] Đang khởi Δ‘α»™ng hệ thα»‘ng phΓ’n tΓ­ch AI...")
print(" [*] Đang nαΊ‘p cΖ‘ sở dα»― liệu thα»‹ trường...")
print(" [*] Hệ thα»‘ng sαΊ½ tα»± Δ‘α»™ng mở trΓ¬nh duyệt sau khi hoΓ n tαΊ₯t.")
print(" ══════════════════════════════════════════════════════════════════════════════════════════════\n")
# Import the FastAPI app
try:
from main import app
except ImportError:
# If running from within the backend folder
sys.path.append(os.path.dirname(__file__))
from main import app
def open_browser():
"""Wait for the server to start and then open the browser."""
# Give the server a few seconds to initialize
time.sleep(2.5)
url = "http://127.0.0.1:8000"
logger.info(f"KαΊΏt nα»‘i thΓ nh cΓ΄ng! Đang mở bαΊ£ng Δ‘iều khiển tαΊ‘i {url}...")
webbrowser.open(url)
if __name__ == "__main__":
print_banner()
# Start the browser opener in a separate thread
threading.Thread(target=open_browser, daemon=True).start()
# Run the uvicorn server
logger.info("Khởi Δ‘α»™ng Backend Core...")
try:
# Hide the detailed uvicorn logs for a cleaner professional feel,
# or keep them for transparency. Let's use 'warning' level for uvicorn
# but keep our own logs at 'info'.
uvicorn.run(app, host="127.0.0.1", port=8000, log_level="warning")
except Exception as e:
logger.error(f"Lα»—i khởi Δ‘α»™ng hệ thα»‘ng: {e}")
print("\n [!] CΓ³ lα»—i xαΊ£y ra trong quΓ‘ trΓ¬nh khởi Δ‘α»™ng.")
print(" [!] NhαΊ₯n Enter để xem chi tiαΊΏt lα»—i vΓ  thoΓ‘t...")
input()