import subprocess import threading import uvicorn from fastapi import FastAPI app = FastAPI() @app.get("/") def home(): # Hugging Face health checker hits this path. # Returning "OK" tells HF the Space is successfully "Running"! return {"status": "Bot is alive"} def run_lichess_bot(): print("Launching Lichess Bot process...") # This fires off your actual lichess-bot script in the background subprocess.run(["python", "lichess-bot-master/lichess-bot.py"]) if __name__ == "__main__": # 1. Start the lichess bot inside a background thread so it doesn't block the website bot_thread = threading.Thread(target=run_lichess_bot, daemon=True) bot_thread.start() # 2. Start the dummy web server on port 7860 that Hugging Face wants to see print("Starting health-check web server on port 7860...") uvicorn.run(app, host="0.0.0.0", port=7860)