dragonxd1 commited on
Commit
3355f04
·
verified ·
1 Parent(s): e9ee9c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -1,16 +1,36 @@
1
- FROM python:3.10-slim
 
 
 
2
 
3
- RUN apt-get update && apt-get install -y git
4
 
5
- WORKDIR /app
 
 
6
 
7
- COPY requirements.txt .
 
 
 
8
 
9
- RUN pip install --no-cache-dir -r requirements.txt
10
- RUN pip install fastapi uvicorn
 
 
11
 
12
- COPY app.py .
 
13
 
14
- EXPOSE 7860
 
 
 
15
 
16
- CMD ["python", "app.py"]
 
 
 
 
 
 
 
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
 
12
+ def clone_repo():
13
+ if not os.path.exists("repo"):
14
+ repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
15
+ subprocess.run(["git", "clone", repo_url, "repo"], check=True)
16
 
17
+ def install_requirements():
18
+ req_file = "repo/requirements.txt"
19
+ if os.path.exists(req_file):
20
+ subprocess.run(["pip", "install", "--no-cache-dir", "-r", req_file], check=True)
21
 
22
+ def start_script():
23
+ subprocess.Popen(["bash", "start"], cwd="repo")
24
 
25
+ def run_app():
26
+ clone_repo()
27
+ install_requirements()
28
+ start_script()
29
 
30
+ @app.on_event("startup")
31
+ def startup_event():
32
+ threading.Thread(target=run_app).start()
33
+
34
+ @app.get("/")
35
+ def home():
36
+ return {"status": "Repo cloned, requirements installed, start script running 🚀"}