Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
from fastapi import BackgroundTasks,
|
| 5 |
from fastapi.responses import RedirectResponse
|
| 6 |
|
| 7 |
-
from azure.storage.blob import
|
| 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
|
| 32 |
try:
|
| 33 |
-
print(msg)
|
| 34 |
print("For processing...")
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
with open('
|
| 38 |
-
|
| 39 |
-
file.write(blob_data.readall())
|
| 40 |
pipe.model.config.forced_decoder_ids = [[2, transcribe_token_id]]
|
| 41 |
print("Call pipeline...")
|
| 42 |
-
text = pipe('
|
| 43 |
print(text)
|
| 44 |
-
except
|
| 45 |
-
print(
|
| 46 |
|
| 47 |
-
@app.
|
| 48 |
async def transcribe(background_tasks: BackgroundTasks):
|
| 49 |
-
background_tasks.add_task(
|
| 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")
|