Spaces:
Sleeping
Sleeping
Yarik
commited on
Commit
·
c0deafa
1
Parent(s):
0ff75c2
Add application file
Browse files
app.py
CHANGED
@@ -5,14 +5,14 @@ import threading
|
|
5 |
import tempfile
|
6 |
import ctypes
|
7 |
import gc
|
8 |
-
from
|
9 |
-
from fastapi import FastAPI, Depends, HTTPException
|
10 |
from fastapi.responses import FileResponse, JSONResponse
|
11 |
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
|
|
|
|
12 |
from pydantic import BaseModel
|
13 |
from huggingface_hub import hf_hub_download
|
14 |
from torch import no_grad, package
|
15 |
-
from pydub import AudioSegment
|
16 |
import uvicorn
|
17 |
from accentor import accentification, stress_replace_and_shift
|
18 |
import argparse
|
@@ -133,6 +133,28 @@ class ArgParser(argparse.ArgumentParser):
|
|
133 |
)
|
134 |
self.args = self.parse_args(sys.argv[1:])
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
if __name__ == "__main__":
|
137 |
args = ArgParser().args
|
138 |
uvicorn.run(app, host=args.server, port=args.port, reload=False)
|
|
|
5 |
import tempfile
|
6 |
import ctypes
|
7 |
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
|
|
|
16 |
import uvicorn
|
17 |
from accentor import accentification, stress_replace_and_shift
|
18 |
import argparse
|
|
|
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 |
+
if api_key_header == api_key:
|
141 |
+
return api_key_header
|
142 |
+
raise HTTPException(
|
143 |
+
status_code=403,
|
144 |
+
detail="Could not validate credentials",
|
145 |
+
)
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
@app.get("/docs", include_in_schema=False)
|
150 |
+
async def get_docs(api_key: str = Depends(getAPIKey)):
|
151 |
+
return get_swagger_ui_html(openapi_url=app.openapi_url, title="docs")
|
152 |
+
|
153 |
+
@app.get("/redoc", include_in_schema=False)
|
154 |
+
async def get_redoc(api_key: str = Depends(getAPIKey)):
|
155 |
+
return get_redoc_html(openapi_url=app.openapi_url, title="docs")
|
156 |
+
|
157 |
+
|
158 |
if __name__ == "__main__":
|
159 |
args = ArgParser().args
|
160 |
uvicorn.run(app, host=args.server, port=args.port, reload=False)
|