Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
# Load the model
|
5 |
-
pipe = pipeline("automatic-speech-recognition", model="
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Define the inference function
|
8 |
def transcribe_audio(audio):
|
@@ -10,8 +16,16 @@ def transcribe_audio(audio):
|
|
10 |
return "No audio file uploaded. Please try again."
|
11 |
|
12 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Perform transcription
|
14 |
-
|
|
|
15 |
return result
|
16 |
except Exception as e:
|
17 |
return f"Error during transcription: {str(e)}"
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from faster_whisper import WhisperModel
|
4 |
+
import librosa
|
5 |
|
6 |
# Load the model
|
7 |
+
# pipe = pipeline("automatic-speech-recognition", model="navidved/persian-whisper-large-v3-ct2")
|
8 |
+
model = WhisperModel("navidved/persian-whisper-large-v3-ct2", device="cpu", compute_type="int8")
|
9 |
+
|
10 |
+
# Define the maximum audio length in seconds
|
11 |
+
MAX_AUDIO_LENGTH = 40 # 40 seconds
|
12 |
|
13 |
# Define the inference function
|
14 |
def transcribe_audio(audio):
|
|
|
16 |
return "No audio file uploaded. Please try again."
|
17 |
|
18 |
try:
|
19 |
+
audio_data, sr = librosa.load(audio, sr=None)
|
20 |
+
duration = librosa.get_duration(y=audio_data, sr=sr)
|
21 |
+
|
22 |
+
# Check if the audio is longer than the allowed duration
|
23 |
+
if duration > MAX_AUDIO_LENGTH:
|
24 |
+
return f"Audio is too long. Please upload an audio file shorter than {MAX_AUDIO_LENGTH} seconds."
|
25 |
+
|
26 |
# Perform transcription
|
27 |
+
segments, _ = model.transcribe(audio, vad_filter=True)
|
28 |
+
result = segments.text
|
29 |
return result
|
30 |
except Exception as e:
|
31 |
return f"Error during transcription: {str(e)}"
|