Spaces:
Running
Running
Update whisper.py
Browse files- whisper.py +13 -9
whisper.py
CHANGED
@@ -1,26 +1,30 @@
|
|
1 |
-
from fastapi import APIRouter, Depends
|
2 |
-
from fastapi.responses import StreamingResponse
|
3 |
-
import io
|
4 |
-
import requests
|
5 |
import os
|
6 |
-
|
|
|
7 |
from pydantic import BaseModel
|
|
|
8 |
from models import *
|
9 |
|
10 |
class WhisperX(BaseModel):
|
11 |
filename: str
|
12 |
-
|
13 |
router = APIRouter()
|
14 |
|
15 |
load_dotenv()
|
16 |
HUGGING_TOKEN = os.environ["HUGGING_TOKEN"]
|
17 |
|
18 |
async def whsiper_to_text(filename):
|
|
|
|
|
|
|
|
|
19 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
20 |
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
|
|
21 |
with open(filename, "rb") as f:
|
22 |
-
|
23 |
-
|
|
|
24 |
if response.status_code != 200:
|
25 |
print(f"Error status {response.status_code}")
|
26 |
return None
|
@@ -33,7 +37,7 @@ async def whsiper_new(payload: WhisperX):
|
|
33 |
if response_data is None:
|
34 |
return SuccessResponse(
|
35 |
status="False",
|
36 |
-
randydev={"error": "Failed to
|
37 |
)
|
38 |
|
39 |
return SuccessResponse(
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import requests
|
3 |
+
from fastapi import APIRouter
|
4 |
from pydantic import BaseModel
|
5 |
+
from dotenv import load_dotenv
|
6 |
from models import *
|
7 |
|
8 |
class WhisperX(BaseModel):
|
9 |
filename: str
|
10 |
+
|
11 |
router = APIRouter()
|
12 |
|
13 |
load_dotenv()
|
14 |
HUGGING_TOKEN = os.environ["HUGGING_TOKEN"]
|
15 |
|
16 |
async def whsiper_to_text(filename):
|
17 |
+
if not os.path.isfile(filename):
|
18 |
+
print(f"Error: File {filename} does not exist.")
|
19 |
+
return None
|
20 |
+
|
21 |
API_URL = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
22 |
headers = {"Authorization": f"Bearer {HUGGING_TOKEN}"}
|
23 |
+
|
24 |
with open(filename, "rb") as f:
|
25 |
+
files = {'file': f}
|
26 |
+
response = requests.post(API_URL, headers=headers, files=files)
|
27 |
+
|
28 |
if response.status_code != 200:
|
29 |
print(f"Error status {response.status_code}")
|
30 |
return None
|
|
|
37 |
if response_data is None:
|
38 |
return SuccessResponse(
|
39 |
status="False",
|
40 |
+
randydev={"error": f"Failed to whisper the filename '{payload.filename}'"}
|
41 |
)
|
42 |
|
43 |
return SuccessResponse(
|