Kavin1701 commited on
Commit
084f96b
·
verified ·
1 Parent(s): 56d13ce

initial uploads

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. fastapi_app.py +45 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ WORKDIR /python-docker
4
+
5
+ COPY requirements.txt requirements.txt
6
+ RUN apt-get update && apt-get install git -y
7
+ RUN pip3 install -r requirements.txt
8
+ RUN pip3 install "git+https://github.com/openai/whisper.git"
9
+ RUN apt-get update && apt-get install -y ffmpeg
10
+
11
+ COPY . .
12
+
13
+ EXPOSE 8000
14
+
15
+ CMD ["uvicorn", "fastapi_app:app", "--host", "0.0.0.0", "--port", "8000"]
fastapi_app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile, HTTPException
2
+ from fastapi.responses import JSONResponse, RedirectResponse
3
+ from tempfile import NamedTemporaryFile
4
+ import whisper
5
+ import torch
6
+ from typing import List
7
+
8
+ # Checking if NVIDIA GPU is available
9
+ DEVICE = "cpu"
10
+
11
+ # Load the Whisper model:
12
+ model = whisper.load_model("base", device=DEVICE)
13
+
14
+ app = FastAPI()
15
+
16
+ @app.post("/whisper/")
17
+ async def handler(files: List[UploadFile] = File(...)):
18
+ if not files:
19
+ raise HTTPException(status_code=400, detail="No files were provided")
20
+
21
+ # For each file, let's store the results in a list of dictionaries.
22
+ results = []
23
+
24
+ for file in files:
25
+ # Create a temporary file.
26
+ with NamedTemporaryFile(delete=True) as temp:
27
+ # Write the user's uploaded file to the temporary file.
28
+ with open(temp.name, "wb") as temp_file:
29
+ temp_file.write(file.file.read())
30
+
31
+ # Let's get the transcript of the temporary file.
32
+ result = model.transcribe(temp.name)
33
+
34
+ # Now we can store the result object for this file.
35
+ results.append({
36
+ 'filename': file.filename,
37
+ 'transcript': result['text'],
38
+ })
39
+
40
+ return JSONResponse(content={'results': results})
41
+
42
+
43
+ @app.get("/", response_class=RedirectResponse)
44
+ async def redirect_to_docs():
45
+ return "/docs"
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ aiofiles
3
+ python-multipart
4
+ uvicorn