yanielbf commited on
Commit
bbec1a4
·
1 Parent(s): 6632ea8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -1
main.py CHANGED
@@ -1,7 +1,11 @@
1
  import torch
2
- from fastapi import BackgroundTasks, File, UploadFile, FastAPI
3
  from transformers import pipeline
4
 
 
 
 
 
 
5
  MODEL_NAME = "openai/whisper-large-v2"
6
 
7
  device = 0 if torch.cuda.is_available() else "cpu"
@@ -27,6 +31,16 @@ def transcribe(file):
27
 
28
  app = FastAPI()
29
 
 
 
 
 
 
 
 
 
 
 
30
  @app.get("/transcribe")
31
  def transcribe(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
32
  background_tasks.add_task(transcribe, file)
 
1
  import torch
 
2
  from transformers import pipeline
3
 
4
+ from fastapi import BackgroundTasks, File, UploadFile, FastAPI
5
+ from fastapi.openapi.utils import get_openapi
6
+ from fastapi.staticfiles import StaticFiles
7
+ from fastapi.openapi.docs import get_swagger_ui_html
8
+
9
  MODEL_NAME = "openai/whisper-large-v2"
10
 
11
  device = 0 if torch.cuda.is_available() else "cpu"
 
31
 
32
  app = FastAPI()
33
 
34
+ app.mount("/", StaticFiles(directory="swagger"), name="swagger")
35
+
36
+ @app.get("/docs", include_in_schema=False)
37
+ async def override_swagger():
38
+ return get_swagger_ui_html(openapi_url="/openapi.json", title="API Docs")
39
+
40
+ @app.get("/openapi.json", include_in_schema=False)
41
+ async def get_open_api_endpoint():
42
+ return get_openapi(title="API Docs", version="1.0.0", routes=app.routes)
43
+
44
  @app.get("/transcribe")
45
  def transcribe(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
46
  background_tasks.add_task(transcribe, file)