radinhas commited on
Commit
25b06cb
1 Parent(s): b6705fa

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. apis/chat_api.py +6 -3
apis/chat_api.py CHANGED
@@ -17,6 +17,7 @@ import re
17
  import requests
18
  from utils.enver import enver
19
  import shutil
 
20
 
21
 
22
  from fastapi import FastAPI, Response, File, UploadFile, Form
@@ -31,7 +32,8 @@ from googletrans import Translator
31
  from io import BytesIO
32
  from gtts import gTTS
33
  from fastapi.middleware.cors import CORSMiddleware
34
-
 
35
 
36
  class ChatAPIApp:
37
  def __init__(self):
@@ -309,7 +311,7 @@ app.add_middleware(
309
  )
310
  @app.post("/transcribe")
311
  async def whisper_transcribe(
312
- audio_file: bytes = File(description="Audio file for transcribe"),
313
  language: str = Form(),
314
  model: str = Form(),
315
  ):
@@ -346,7 +348,8 @@ async def whisper_transcribe(
346
  )
347
  time_start = time.time()
348
  pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=language, task="transcribe")
349
- text = pipe(audio_file)["text"]
 
350
  time_end = time.time()
351
  item_response["status"] = 200
352
  item_response["result"] = text
 
17
  import requests
18
  from utils.enver import enver
19
  import shutil
20
+ import tempfile
21
 
22
 
23
  from fastapi import FastAPI, Response, File, UploadFile, Form
 
32
  from io import BytesIO
33
  from gtts import gTTS
34
  from fastapi.middleware.cors import CORSMiddleware
35
+ from pathlib import Path
36
+ from tempfile import NamedTemporaryFile
37
 
38
  class ChatAPIApp:
39
  def __init__(self):
 
311
  )
312
  @app.post("/transcribe")
313
  async def whisper_transcribe(
314
+ audio_file: UploadFile = File(description="Audio file for transcribe"),
315
  language: str = Form(),
316
  model: str = Form(),
317
  ):
 
348
  )
349
  time_start = time.time()
350
  pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=language, task="transcribe")
351
+ file_data = await audio_file.read()
352
+ text = pipe(file_data)["text"]
353
  time_end = time.time()
354
  item_response["status"] = 200
355
  item_response["result"] = text