Spaces:
Build error
Build error
| import os | |
| import subprocess | |
| import sys | |
| import time | |
| import threading | |
| def install_dependencies(): | |
| print("π Installing dependencies...") | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "pyngrok", "nest_asyncio", "uvicorn"]) | |
| def run_server(): | |
| print("π₯ Starting FastAPI Server...") | |
| # Run server.py using python command to ensure it runs as a script | |
| subprocess.run([sys.executable, "server.py"], check=True) | |
| def start_ngrok(): | |
| from pyngrok import ngrok | |
| token = input("π Enter your Ngrok Authtoken (from https://dashboard.ngrok.com/get-started/your-authtoken): ") | |
| if not token: | |
| print("β Error: Ngrok token is required.") | |
| return | |
| ngrok.set_auth_token(token) | |
| # Start tunnel to port 8000 | |
| public_url = ngrok.connect(8000).public_url | |
| print(f"\nβ \033[92mPublic Backend URL: {public_url}\033[0m") | |
| print("π Copy this URL and paste it into the 'Backend Connection' box on your Vercel website.\n") | |
| # Keep functionality alive | |
| try: | |
| # Run server in main thread or subprocess | |
| run_server() | |
| except KeyboardInterrupt: | |
| print("Stopping...") | |
| ngrok.kill() | |
| if __name__ == "__main__": | |
| if not os.path.exists("server.py"): | |
| print("β Error: server.py not found. Make sure you are in the root of the cloned repository.") | |
| else: | |
| try: | |
| install_dependencies() | |
| print("β Dependencies installed.") | |
| start_ngrok() | |
| except Exception as e: | |
| print(f"β Error: {e}") | |