Karthikeyaandhoju commited on
Commit
82fb1db
1 Parent(s): 5dfb369

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from transformers import pipeline
3
+ from pydantic import BaseModel
4
+ import os
5
+
6
+ # Load the Whisper model for transcription
7
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
8
+
9
+ app = FastAPI()
10
+
11
+ class TranscriptionResponse(BaseModel):
12
+ text: str
13
+
14
+ @app.post("/transcribe/", response_model=TranscriptionResponse)
15
+ async def transcribe(file_name: str):
16
+ file_path = os.path.join("/app/audio_files", file_name) # Assuming audio files are stored in /app/audio_files directory
17
+
18
+ # Check if file exists
19
+ if not os.path.exists(file_path):
20
+ raise HTTPException(status_code=404, detail="File not found")
21
+
22
+ # Read the file content
23
+ with open(file_path, "rb") as audio_file:
24
+ audio_content = audio_file.read()
25
+
26
+ # Perform the transcription
27
+ transcription = transcriber(audio_content)["text"]
28
+
29
+ return TranscriptionResponse(text=transcription)
30
+
31
+ if __name__ == "__main__":
32
+ import uvicorn
33
+ uvicorn.run(app, host="0.0.0.0", port=7860)