File size: 804 Bytes
bec06d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Hugging Face Spaces entry point for the backend API

import os
import sys
from threading import Thread
from time import sleep

# Add the parent directory to path for imports
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

from backend.api import app

if __name__ == "__main__":
    # Start the Flask app in a separate thread
    # This is needed because Hugging Face Spaces may require the main thread for other purposes
    def run_app():
        app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)), debug=False)
    
    # Start the Flask app in a separate thread
    thread = Thread(target=run_app)
    thread.start()
    
    # Keep the main thread alive
    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        print("Shutting down...")