Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 2 |
+
import librosa
|
| 3 |
+
|
| 4 |
+
# Load model and processor
|
| 5 |
+
device = "cuda"
|
| 6 |
+
processor = WhisperProcessor.from_pretrained("jiviai/audioX-south-v1")
|
| 7 |
+
model = WhisperForConditionalGeneration.from_pretrained("jiviai/audioX-south-v1").to(device)
|
| 8 |
+
model.config.forced_decoder_ids = None
|
| 9 |
+
|
| 10 |
+
# Load and preprocess audio
|
| 11 |
+
audio_path = "sample.wav"
|
| 12 |
+
audio_np, sr = librosa.load(audio_path, sr=None)
|
| 13 |
+
if sr != 16000:
|
| 14 |
+
audio_np = librosa.resample(audio_np, orig_sr=sr, target_sr=16000)
|
| 15 |
+
|
| 16 |
+
input_features = processor(audio_np, sampling_rate=16000, return_tensors="pt").to(device).input_features
|
| 17 |
+
|
| 18 |
+
# Generate predictions
|
| 19 |
+
# Use ISO 639-1 language codes: "hi", "mr", "gu" for North; "ta", "te", "kn", "ml" for South
|
| 20 |
+
# Or omit the language argument for automatic language detection
|
| 21 |
+
predicted_ids = model.generate(input_features, task="transcribe", language="ta")
|
| 22 |
+
|
| 23 |
+
# Decode predictions
|
| 24 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 25 |
+
print(transcription)
|