Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,23 +5,19 @@ from fastapi import FastAPI, Request
|
|
| 5 |
from fastapi.responses import JSONResponse, HTMLResponse
|
| 6 |
import httpx
|
| 7 |
|
| 8 |
-
app = FastAPI(docs_url=None, redoc_url=None)
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
# Your userbot's internal port
|
| 15 |
USERBOT_API_PORT = 8888
|
| 16 |
|
| 17 |
def clone_repo():
|
| 18 |
if not os.path.exists("repo"):
|
| 19 |
-
|
| 20 |
-
repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
|
| 21 |
-
else:
|
| 22 |
-
repo_url = f"https://github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
|
| 23 |
-
|
| 24 |
-
print(f"Cloning repo: {GITHUB_USERNAME}/{REPO_NAME}")
|
| 25 |
subprocess.run(["git", "clone", repo_url, "repo"], check=True)
|
| 26 |
|
| 27 |
def install_requirements():
|
|
@@ -66,7 +62,7 @@ async def proxy_docs(request: Request):
|
|
| 66 |
response = await client.get(f"http://127.0.0.1:{USERBOT_API_PORT}/docs", headers=headers)
|
| 67 |
return HTMLResponse(status_code=response.status_code, content=response.content)
|
| 68 |
except Exception:
|
| 69 |
-
return
|
| 70 |
|
| 71 |
# Forward OpenAPI schema (Swagger UI needs this)
|
| 72 |
@app.get("/openapi.json")
|
|
|
|
| 5 |
from fastapi.responses import JSONResponse, HTMLResponse
|
| 6 |
import httpx
|
| 7 |
|
| 8 |
+
app = FastAPI(docs_url=None, redoc_url=None)
|
| 9 |
|
| 10 |
+
# Use .strip() to remove any accidental newlines or spaces from HF Secrets!
|
| 11 |
+
GITHUB_USERNAME = os.getenv("GITHUB_USERNAME", "").strip()
|
| 12 |
+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", "").strip()
|
| 13 |
+
REPO_NAME = os.getenv("REPO_NAME", "").strip()
|
| 14 |
|
| 15 |
# Your userbot's internal port
|
| 16 |
USERBOT_API_PORT = 8888
|
| 17 |
|
| 18 |
def clone_repo():
|
| 19 |
if not os.path.exists("repo"):
|
| 20 |
+
repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
subprocess.run(["git", "clone", repo_url, "repo"], check=True)
|
| 22 |
|
| 23 |
def install_requirements():
|
|
|
|
| 62 |
response = await client.get(f"http://127.0.0.1:{USERBOT_API_PORT}/docs", headers=headers)
|
| 63 |
return HTMLResponse(status_code=response.status_code, content=response.content)
|
| 64 |
except Exception:
|
| 65 |
+
return HTMLResponse(status_code=503, content="<h1>Userbot API is booting up... Refresh in 5 seconds!</h1>")
|
| 66 |
|
| 67 |
# Forward OpenAPI schema (Swagger UI needs this)
|
| 68 |
@app.get("/openapi.json")
|