Spaces:
Paused
Paused
| import os | |
| import subprocess | |
| from fastapi import FastAPI | |
| import threading | |
| app = FastAPI() | |
| GITHUB_USERNAME = os.getenv("GITHUB_USERNAME") | |
| GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") | |
| REPO_NAME = os.getenv("REPO_NAME") | |
| def clone_repo(): | |
| if not os.path.exists("repo"): | |
| repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git" | |
| subprocess.run(["git", "clone", repo_url, "repo"], check=True) | |
| def install_requirements(): | |
| req_file = "repo/requirements.txt" | |
| if os.path.exists(req_file): | |
| subprocess.run(["pip", "install", "--no-cache-dir", "-r", req_file], check=True) | |
| def start_script(): | |
| subprocess.Popen(["bash", "start"], cwd="repo") | |
| def run_app(): | |
| clone_repo() | |
| install_requirements() | |
| start_script() | |
| def startup_event(): | |
| threading.Thread(target=run_app).start() | |
| def home(): | |
| return {"status": "Repo cloned, requirements installed, start script running 🚀"} |