Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,13 +6,6 @@ import logging
|
|
| 6 |
logging.basicConfig()
|
| 7 |
logging.getLogger("faster_whisper").setLevel(logging.DEBUG)
|
| 8 |
|
| 9 |
-
# Initialize the Whisper model with your desired configuration
|
| 10 |
-
model_size = "large-v3" # Choose the model size
|
| 11 |
-
device = "cpu" # GPU : cuda CPU : cpu
|
| 12 |
-
compute_type = "int8" # GPU : float16 or int8 - CPU : int8
|
| 13 |
-
|
| 14 |
-
model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
| 15 |
-
|
| 16 |
def format_timestamp(seconds):
|
| 17 |
"""Convert seconds to HH:MM:SS.mmm format."""
|
| 18 |
hours = int(seconds // 3600)
|
|
@@ -20,7 +13,13 @@ def format_timestamp(seconds):
|
|
| 20 |
seconds_remainder = seconds % 60
|
| 21 |
return f"{hours:02d}:{minutes:02d}:{seconds_remainder:06.3f}"
|
| 22 |
|
| 23 |
-
def transcribe(audio_file):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
# Transcribe the audio file
|
| 25 |
segments, _ = model.transcribe(audio_file)
|
| 26 |
|
|
@@ -32,14 +31,14 @@ def transcribe(audio_file):
|
|
| 32 |
|
| 33 |
return "\n".join(transcription_with_timestamps)
|
| 34 |
|
| 35 |
-
# Define the Gradio interface
|
| 36 |
iface = gr.Interface(fn=transcribe,
|
| 37 |
-
inputs=gr.Audio(sources="upload", type="filepath", label="Upload Audio"),
|
|
|
|
| 38 |
outputs="text",
|
| 39 |
-
title="Whisper
|
| 40 |
-
description="
|
| 41 |
|
| 42 |
# Launch the app
|
| 43 |
if __name__ == "__main__":
|
| 44 |
iface.launch()
|
| 45 |
-
|
|
|
|
| 6 |
logging.basicConfig()
|
| 7 |
logging.getLogger("faster_whisper").setLevel(logging.DEBUG)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def format_timestamp(seconds):
|
| 10 |
"""Convert seconds to HH:MM:SS.mmm format."""
|
| 11 |
hours = int(seconds // 3600)
|
|
|
|
| 13 |
seconds_remainder = seconds % 60
|
| 14 |
return f"{hours:02d}:{minutes:02d}:{seconds_remainder:06.3f}"
|
| 15 |
|
| 16 |
+
def transcribe(audio_file, model_size):
|
| 17 |
+
# Initialize the Whisper model based on the selected model size
|
| 18 |
+
device = "cpu" # GPU : cuda CPU : cpu
|
| 19 |
+
compute_type = "int8" # GPU : float16 or int8 - CPU : int8
|
| 20 |
+
|
| 21 |
+
model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
| 22 |
+
|
| 23 |
# Transcribe the audio file
|
| 24 |
segments, _ = model.transcribe(audio_file)
|
| 25 |
|
|
|
|
| 31 |
|
| 32 |
return "\n".join(transcription_with_timestamps)
|
| 33 |
|
| 34 |
+
# Define the Gradio interface with a dropdown for model selection
|
| 35 |
iface = gr.Interface(fn=transcribe,
|
| 36 |
+
inputs=[gr.Audio(sources="upload", type="filepath", label="Upload Audio"),
|
| 37 |
+
gr.Dropdown(choices=["base", "small", "medium", "large", "large-v2", "large-v3"], label="Model Size")],
|
| 38 |
outputs="text",
|
| 39 |
+
title="Whisper API",
|
| 40 |
+
description="For web use please visit [this space](https://huggingface.co/spaces/Lenylvt/Whisper)")
|
| 41 |
|
| 42 |
# Launch the app
|
| 43 |
if __name__ == "__main__":
|
| 44 |
iface.launch()
|
|
|