-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
40 lines (27 loc) · 1.15 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import List
from fastapi import FastAPI, File, UploadFile, Request, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from manage import Manager
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.post("/upload/", response_class=HTMLResponse)
async def create_upload_files(request: Request, files: List[UploadFile] = File(...)):
filenames = [file.filename for file in files]
if not filenames[0]:
raise HTTPException(
status_code=400, detail="Please select a file to upload!")
audio = await files[0].read()
manager = Manager(audio)
manager.convert_audio()
manager.denoise_input()
manager.separate()
transcript = manager.create_transcript()
return templates.TemplateResponse("index.html",
{'request': request,
'en_transcript': transcript["transcriptions"][0]["utf_text_en"],
'hi_transcript': transcript["transcriptions"][0]["utf_text"]
})
@app.get("/", response_class=HTMLResponse)
async def index(request: Request):
return templates.TemplateResponse("index.html", {'request': request})