legusxyz commited on
Commit
4652073
·
verified ·
1 Parent(s): 906b9e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -8,6 +8,30 @@ app = FastAPI()
8
  def read_root():
9
  return {"message": "Welcome to the FastAPI app on Hugging Face Spaces!"}
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # If running as the main module, start Uvicorn
12
  if __name__ == "__main__":
13
  import uvicorn
 
8
  def read_root():
9
  return {"message": "Welcome to the FastAPI app on Hugging Face Spaces!"}
10
 
11
+ @app.post("/transcribe/")
12
+ async def transcribe_audio(file: UploadFile = File(...)):
13
+ start_time = time.time()
14
+
15
+ # Save the uploaded file using a temporary file manager
16
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio_file:
17
+ temp_file_path = temp_audio_file.name
18
+ temp_audio_file.write(await file.read())
19
+
20
+ # Transcribe the audio
21
+ transcription_start = time.time()
22
+ transcription = asr_pipeline(temp_file_path)
23
+ transcription_end = time.time()
24
+
25
+ # Clean up temporary file after use
26
+ os.remove(temp_file_path)
27
+
28
+ # Log time durations
29
+ end_time = time.time()
30
+ print(f"Time to transcribe audio: {transcription_end - transcription_start:.4f} seconds")
31
+ print(f"Total execution time: {end_time - start_time:.4f} seconds")
32
+
33
+ return {"transcription": transcription['text']}
34
+
35
  # If running as the main module, start Uvicorn
36
  if __name__ == "__main__":
37
  import uvicorn