yanielbf commited on
Commit
cc712ab
·
1 Parent(s): dd94e79

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -14
main.py CHANGED
@@ -1,10 +1,17 @@
 
 
 
 
 
 
 
1
  import torch
2
  from transformers import pipeline
3
 
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=="
@@ -28,25 +35,23 @@ translate_token_id = all_special_ids[-6]
28
 
29
  app = FastAPI()
30
 
31
- def transcribe(msg):
32
  try:
33
- print(msg)
34
  print("For processing...")
35
- blob_service_client_instance = BlobServiceClient(account_url=STORAGEACCOUNTURL, credential=STORAGEACCOUNTKEY)
36
- blob_client_instance = blob_service_client_instance.get_blob_client(CONTAINERNAME, BLOBNAME, snapshot=None)
37
- with open('/home/user/data/audio.mp3', "wb") as file:
38
- blob_data = blob_client_instance.download_blob()
39
- file.write(blob_data.readall())
40
  pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id]]
41
  print("Call pipeline...")
42
- text = pipe('/home/user/data/audio.mp3', return_timestamps=True)
43
  print(text)
44
- except error:
45
- print(error)
46
 
47
- @app.post("/transcribe")
48
  async def transcribe(background_tasks: BackgroundTasks):
49
- background_tasks.add_task(transcribe, msg="Hola")
50
  return {"text": "Processing file..."}
51
 
52
  @app.get("/text")
 
1
+ # import whisper
2
+
3
+ # model = whisper.load_model("medium")
4
+ # options = whisper.DecodingOptions(language="spanish", fp16=False)
5
+ # result = model.transcribe("audio2.mp3", decode_options=options)
6
+ # print(result["text"])
7
+
8
  import torch
9
  from transformers import pipeline
10
 
11
+ from fastapi import BackgroundTasks, FastAPI
12
  from fastapi.responses import RedirectResponse
13
 
14
+ from azure.storage.blob import BlobClient, ContentSettings
15
 
16
  STORAGEACCOUNTURL = "https://callreviewer.blob.core.windows.net"
17
  STORAGEACCOUNTKEY = "vXq0X89zOaQxQmv7UBGFqqa61V0FRE6Gx1TgJvbtxZn5zLJ1ETc9aGDbbotuSoQzf5ob9QTuXlof+AStdHXOpA=="
 
35
 
36
  app = FastAPI()
37
 
38
+ def transcribe_task():
39
  try:
 
40
  print("For processing...")
41
+ blob = BlobClient(account_url=STORAGEACCOUNTURL,container_name=CONTAINERNAME, blob_name=BLOBNAME,credential=STORAGEACCOUNTKEY)
42
+ blob.set_http_headers(ContentSettings(content_type='audio/mp3'))
43
+ with open('audio22.mp3', "wb") as file:
44
+ file.write(blob.download_blob().readall())
 
45
  pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id]]
46
  print("Call pipeline...")
47
+ text = pipe('audio22.mp3', return_timestamps=True)
48
  print(text)
49
+ except:
50
+ print("Error")
51
 
52
+ @app.get("/transcribe")
53
  async def transcribe(background_tasks: BackgroundTasks):
54
+ background_tasks.add_task(transcribe_task)
55
  return {"text": "Processing file..."}
56
 
57
  @app.get("/text")