Spaces:
Runtime error
Runtime error
BjarneBepaData
commited on
Commit
•
d6378a2
1
Parent(s):
97c3bac
A temporary location
Browse files- app/main.py +4 -2
- requirements.txt +2 -1
app/main.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
import torch
|
|
|
3 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
4 |
|
5 |
app = FastAPI()
|
|
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
@@ -11,11 +13,11 @@ model_id = "openai/whisper-large-v3"
|
|
11 |
|
12 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
13 |
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True,
|
14 |
-
cache_dir=
|
15 |
)
|
16 |
model.to(device)
|
17 |
|
18 |
-
processor = AutoProcessor.from_pretrained(model_id, cache_dir=
|
19 |
|
20 |
pipe = pipeline(
|
21 |
"automatic-speech-recognition",
|
|
|
1 |
from fastapi import FastAPI
|
2 |
import torch
|
3 |
+
import tempdir
|
4 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
5 |
|
6 |
app = FastAPI()
|
7 |
+
temp_dir = tempdir.TemporaryDirectory()
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
|
|
13 |
|
14 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
15 |
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True,
|
16 |
+
cache_dir=temp_dir.name
|
17 |
)
|
18 |
model.to(device)
|
19 |
|
20 |
+
processor = AutoProcessor.from_pretrained(model_id, cache_dir=temp_dir.name)
|
21 |
|
22 |
pipe = pipeline(
|
23 |
"automatic-speech-recognition",
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@
|
|
2 |
fastapi
|
3 |
uvicorn
|
4 |
torch
|
5 |
-
transformers
|
|
|
|
2 |
fastapi
|
3 |
uvicorn
|
4 |
torch
|
5 |
+
transformers
|
6 |
+
tempdir
|