File size: 888 Bytes
9d73c27
06c347a
 
 
9d73c27
06c347a
9d73c27
06c347a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)