Spaces:
Sleeping
Sleeping
Yarik
commited on
Commit
•
ca466ef
1
Parent(s):
7833469
Add application file
Browse files
app.py
CHANGED
@@ -8,8 +8,6 @@ import gc
|
|
8 |
from fastapi import FastAPI, Depends, HTTPException, Security
|
9 |
from fastapi.responses import FileResponse, JSONResponse
|
10 |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
11 |
-
from fastapi.security.api_key import APIKeyHeader
|
12 |
-
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
|
13 |
from pydantic import BaseModel
|
14 |
from huggingface_hub import hf_hub_download
|
15 |
from torch import no_grad, package
|
@@ -18,7 +16,7 @@ from accentor import accentification, stress_replace_and_shift
|
|
18 |
import argparse
|
19 |
from passlib.context import CryptContext
|
20 |
|
21 |
-
app = FastAPI()
|
22 |
|
23 |
# Set environment variable for Hugging Face cache directory
|
24 |
os.environ["HF_HOME"] = "/app/.cache"
|
@@ -133,29 +131,6 @@ class ArgParser(argparse.ArgumentParser):
|
|
133 |
)
|
134 |
self.args = self.parse_args(sys.argv[1:])
|
135 |
|
136 |
-
|
137 |
-
api_key_header = APIKeyHeader(name="access_token", auto_error=False)
|
138 |
-
|
139 |
-
def getAPIKey(api_key_header: str = Security(api_key_header)):
|
140 |
-
print(api_key_header)
|
141 |
-
if api_key_header == api_key:
|
142 |
-
return api_key_header
|
143 |
-
raise HTTPException(
|
144 |
-
status_code=403,
|
145 |
-
detail="Could not validate credentials",
|
146 |
-
)
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
@app.get("/docs", include_in_schema=False)
|
151 |
-
async def get_docs(api_key: str = Depends(getAPIKey)):
|
152 |
-
return get_swagger_ui_html(openapi_url=app.openapi_url, title="docs")
|
153 |
-
|
154 |
-
@app.get("/redoc", include_in_schema=False)
|
155 |
-
async def get_redoc(api_key: str = Depends(getAPIKey)):
|
156 |
-
return get_redoc_html(openapi_url=app.openapi_url, title="docs")
|
157 |
-
|
158 |
-
|
159 |
if __name__ == "__main__":
|
160 |
args = ArgParser().args
|
161 |
uvicorn.run(app, host=args.server, port=args.port, reload=False)
|
|
|
8 |
from fastapi import FastAPI, Depends, HTTPException, Security
|
9 |
from fastapi.responses import FileResponse, JSONResponse
|
10 |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
|
|
|
|
11 |
from pydantic import BaseModel
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
from torch import no_grad, package
|
|
|
16 |
import argparse
|
17 |
from passlib.context import CryptContext
|
18 |
|
19 |
+
app = FastAPI(docs_url=None, redoc_url=None)
|
20 |
|
21 |
# Set environment variable for Hugging Face cache directory
|
22 |
os.environ["HF_HOME"] = "/app/.cache"
|
|
|
131 |
)
|
132 |
self.args = self.parse_args(sys.argv[1:])
|
133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
if __name__ == "__main__":
|
135 |
args = ArgParser().args
|
136 |
uvicorn.run(app, host=args.server, port=args.port, reload=False)
|