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}")