dragonxd1 commited on
Commit
281df92
·
verified ·
1 Parent(s): 80fb2f8

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -44
app.py DELETED
@@ -1,44 +0,0 @@
1
- import os
2
- import subprocess
3
- from fastapi import FastAPI
4
- import threading
5
-
6
- app = FastAPI()
7
-
8
- GITHUB_USERNAME = os.getenv("GITHUB_USERNAME")
9
- GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
10
- REPO_NAME = os.getenv("REPO_NAME")
11
- START_CMD = os.getenv("START_CMD", "python3 -m dragon")
12
-
13
- def clone_repo():
14
- if not os.path.exists("repo"):
15
- if not GITHUB_USERNAME or not REPO_NAME:
16
- raise RuntimeError("GITHUB_USERNAME and REPO_NAME env vars must be set in the Space.")
17
-
18
- if GITHUB_TOKEN:
19
- repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
20
- else:
21
- repo_url = f"https://github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
22
-
23
- subprocess.run(["git", "clone", repo_url, "repo"], check=True)
24
-
25
- def install_requirements():
26
- req_file = "repo/requirements.txt"
27
- if os.path.exists(req_file):
28
- subprocess.run(["pip", "install", "--no-cache-dir", "-r", req_file], check=True)
29
-
30
- def start_script():
31
- subprocess.Popen(START_CMD.split(), cwd="repo")
32
-
33
- def run_app():
34
- clone_repo()
35
- install_requirements()
36
- start_script()
37
-
38
- @app.on_event("startup")
39
- def startup_event():
40
- threading.Thread(target=run_app).start()
41
-
42
- @app.api_route("/", methods=["GET", "HEAD"])
43
- def home():
44
- return {"status": "Repo cloned, requirements installed, start script running 🚀"}