Akash
07/09/2024, 2:26 PMJian Shen Yap
07/09/2024, 4:14 PMAkash
07/10/2024, 4:16 AMimport bentoml
import os
from typing import Any
from LargeTranslate import Transcribe
from pathlib import Path
import shutil
import torch
import time
@bentoml.service(
http = {
"cors" : {
"enabled": True,
"access_control_allow_origins": "*",
"access_control_allow_methods": ["GET", "OPTIONS", "POST", "HEAD", "PUT"],
"access_control_allow_credentials": True,
"access_control_allow_headers": ["*"],
"access_control_allow_origin_regex": "https://.*\.my_org\.com",
"access_control_max_age": 1200,
"access_control_expose_headers": ["Content-Length"]
}
},
traffic={
"timeout": 600,
"max_concurrency": 3,
},
workers = 3,
)
class AsrBentoGPU:
def __init__(self):
self.model = Transcribe()
@bentoml.api
async def transcribe(self, form_data: Path) -> Any:
print("========REQUEST RECEIVED==========")
script_dir = Path(__file__).resolve().parent
# audio_path = os.path.join(script_dir, "uploads")
actual_path = form_data.absolute()
shutil.move(actual_path,script_dir)
audio_final_path = os.path.join(script_dir, form_data.name)
print(100*"*")
print(f"===============cuda is available===================: {torch.cuda.is_available()}")
print(100*"*")
print(f"======================Audio_path===================:{audio_final_path}")
print(100 * "*")
t1 = time.time()
transcription = await self.model.run(audio_final_path)
t2 = time.time()
print(100*"*")
print(f"============Transcription:===================== {transcription}")
print(100*"*")
print(f"==================Inference_time======================: {t2-t1}")
print(100*"*")
if os.path.exists(audio_final_path):
os.remove(audio_final_path)
print(f"====================Deleted file=======================: {audio_final_path}")
return transcriptionAkash
07/10/2024, 7:04 AMJian Shen Yap
07/10/2024, 10:18 PMAkash
07/11/2024, 4:07 AMAkash
07/11/2024, 2:47 PMJian Shen Yap
07/11/2024, 3:20 PMbentoml serve , 3 workers is being spun up?Akash
07/11/2024, 3:22 PMJian Shen Yap
07/11/2024, 3:25 PMAkash
07/11/2024, 3:31 PM