Views
No views yet
1# Specify the CUDA device
2device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
3
4model_id = "eryk7381/whisper-med-pol-car"
5torch_dtype = torch.float16 # You can adjust the dtype if needed
6
7# Load model and move it to CUDA
8model = AutoModelForSpeechSeq2Seq.from_pretrained(
9model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
10)
11model.to(device)
12
13# Load processor
14processor = AutoProcessor.from_pretrained(model_id)
15
16# Create the pipeline with CUDA support
17pipe = pipeline(
18"automatic-speech-recognition",
19model=model,
20tokenizer=processor.tokenizer,
21feature_extractor=processor.feature_extractor,
22max_new_tokens=128,
23chunk_length_s=30,
24batch_size=16,
25return_timestamps=True,
26torch_dtype=torch_dtype,
27device=device,
28)
29audio_path = 'your_audio_path.wav'
30sample = audio_path
31result = pipe(sample, generate_kwargs={"language": "polish"})
32print(result['text'])
33