Update main.py
Browse files
main.py
CHANGED
|
@@ -13,15 +13,15 @@ app = FastAPI()
|
|
| 13 |
|
| 14 |
def process_audio(url: str):
|
| 15 |
response = requests.get(url)
|
| 16 |
-
with open("/
|
| 17 |
file.write(response.content)
|
| 18 |
|
| 19 |
|
| 20 |
-
device = "
|
| 21 |
|
| 22 |
model_id = "openai/whisper-large-v3"
|
| 23 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 24 |
-
model_id, torch_dtype=torch.
|
| 25 |
)
|
| 26 |
model.to(device)
|
| 27 |
|
|
@@ -35,11 +35,11 @@ def process_audio(url: str):
|
|
| 35 |
chunk_length_s=30,
|
| 36 |
batch_size=16,
|
| 37 |
return_timestamps=True,
|
| 38 |
-
torch_dtype=torch.
|
| 39 |
device=device
|
| 40 |
)
|
| 41 |
dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
|
| 42 |
-
whisper_result = pipe("/
|
| 43 |
return whisper_result
|
| 44 |
|
| 45 |
|
|
|
|
| 13 |
|
| 14 |
def process_audio(url: str):
|
| 15 |
response = requests.get(url)
|
| 16 |
+
with open("/data/audio.mp3", mode="wb") as file:
|
| 17 |
file.write(response.content)
|
| 18 |
|
| 19 |
|
| 20 |
+
device = "cuda"
|
| 21 |
|
| 22 |
model_id = "openai/whisper-large-v3"
|
| 23 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 24 |
+
model_id, torch_dtype=torch.float16, low_cpu_mem_usage=True, use_safetensors=True
|
| 25 |
)
|
| 26 |
model.to(device)
|
| 27 |
|
|
|
|
| 35 |
chunk_length_s=30,
|
| 36 |
batch_size=16,
|
| 37 |
return_timestamps=True,
|
| 38 |
+
torch_dtype=torch.float16,
|
| 39 |
device=device
|
| 40 |
)
|
| 41 |
dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
|
| 42 |
+
whisper_result = pipe("/data/audio.mp3")
|
| 43 |
return whisper_result
|
| 44 |
|
| 45 |
|