Spaces:
Build error
Build error
File size: 1,659 Bytes
1b7ef07 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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}")
|