yanielbf commited on
Commit
e92a84a
·
1 Parent(s): 6fed2a5

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -4
main.py CHANGED
@@ -4,6 +4,13 @@ from transformers import pipeline
4
  from fastapi import BackgroundTasks, File, UploadFile, FastAPI
5
  from fastapi.responses import RedirectResponse
6
 
 
 
 
 
 
 
 
7
  MODEL_NAME = "openai/whisper-large-v2"
8
 
9
  device = 0 if torch.cuda.is_available() else "cpu"
@@ -19,12 +26,17 @@ all_special_ids = pipe.tokenizer.all_special_ids
19
  transcribe_token_id = all_special_ids[-5]
20
  translate_token_id = all_special_ids[-6]
21
 
22
- def transcribe(file: UploadFile):
23
  try:
24
  print("For processing...")
 
 
 
 
 
25
  pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id]]
26
  print("Call pipeline...")
27
- text = pipe(file, return_timestamps=True)
28
  print("Save file...")
29
  file_path = '/home/user/data/new_file.txt'
30
  with open(file_path, "w") as file:
@@ -36,8 +48,8 @@ def transcribe(file: UploadFile):
36
  app = FastAPI()
37
 
38
  @app.post("/transcribe")
39
- def transcribe(background_tasks: BackgroundTasks, file: UploadFile = File(...)):
40
- background_tasks.add_task(transcribe, file)
41
  return {"text": "Processing file..."}
42
 
43
  @app.get("/text")
 
4
  from fastapi import BackgroundTasks, File, UploadFile, FastAPI
5
  from fastapi.responses import RedirectResponse
6
 
7
+ from azure.storage.blob import BlobServiceClient
8
+
9
+ STORAGEACCOUNTURL = "https://callreviewer.blob.core.windows.net"
10
+ STORAGEACCOUNTKEY = "vXq0X89zOaQxQmv7UBGFqqa61V0FRE6Gx1TgJvbtxZn5zLJ1ETc9aGDbbotuSoQzf5ob9QTuXlof+AStdHXOpA=="
11
+ CONTAINERNAME = "default"
12
+ BLOBNAME = "audio.mp3"
13
+
14
  MODEL_NAME = "openai/whisper-large-v2"
15
 
16
  device = 0 if torch.cuda.is_available() else "cpu"
 
26
  transcribe_token_id = all_special_ids[-5]
27
  translate_token_id = all_special_ids[-6]
28
 
29
+ def transcribe():
30
  try:
31
  print("For processing...")
32
+ blob_service_client_instance = BlobServiceClient(account_url=STORAGEACCOUNTURL, credential=STORAGEACCOUNTKEY)
33
+ blob_client_instance = blob_service_client_instance.get_blob_client(CONTAINERNAME, BLOBNAME, snapshot=None)
34
+ with open('/home/user/data/audio.mp3', "wb") as file:
35
+ blob_data = blob_client_instance.download_blob()
36
+ file.write(blob_data.readall())
37
  pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id]]
38
  print("Call pipeline...")
39
+ text = pipe('/home/user/data/audio.mp3', return_timestamps=True)
40
  print("Save file...")
41
  file_path = '/home/user/data/new_file.txt'
42
  with open(file_path, "w") as file:
 
48
  app = FastAPI()
49
 
50
  @app.post("/transcribe")
51
+ def transcribe(background_tasks: BackgroundTasks):
52
+ background_tasks.add_task(transcribe)
53
  return {"text": "Processing file..."}
54
 
55
  @app.get("/text")