Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import librosa
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration, pipeline
|
7 |
+
|
8 |
+
processor = WhisperProcessor.from_pretrained("https://huggingface.co/spaces/akadriu/shqip_whisper")
|
9 |
+
model = WhisperForConditionalGeneration.from_pretrained("https://huggingface.co/spaces/akadriu/shqip_whisper")
|
10 |
+
|
11 |
+
def transcribe(audio):
|
12 |
+
audio_input, _ = librosa.load(audio, sr=16000)
|
13 |
+
input_features = processor(audio_input, sampling_rate=16000, return_tensors="pt").input_features
|
14 |
+
predicted_ids = model.generate(input_features)
|
15 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
16 |
+
text = transcription
|
17 |
+
return text
|
18 |
+
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=transcribe,
|
21 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
22 |
+
outputs="text",
|
23 |
+
title="Whisper Medium Shqip",
|
24 |
+
description="Realtime demo for Sq speech recognition using a fine-tuned Whisper medium model.",
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|