Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,14 @@
|
|
1 |
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
import whisper
|
5 |
-
|
6 |
-
import torch
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
print(
|
11 |
|
12 |
-
# Load the Whisper model
|
13 |
model_name = "tiny" # Change to "base", "small", etc., as needed
|
14 |
-
|
15 |
-
print(f"Loading the Whisper model: {model_name} with ZeRO optimization...")
|
16 |
-
with init_empty_weights():
|
17 |
-
whisper_model = whisper.load_model(model_name) # Load model structure without weights
|
18 |
-
|
19 |
-
# Dispatch the model across devices using ZeRO
|
20 |
-
whisper_model = load_checkpoint_and_dispatch(
|
21 |
-
whisper_model,
|
22 |
-
device_map=device_map,
|
23 |
-
dtype=torch.float16 # Use mixed precision for efficiency
|
24 |
-
)
|
25 |
-
|
26 |
-
print("Model successfully loaded with ZeRO optimization!")
|
27 |
|
28 |
# Define the transcription function
|
29 |
def transcribe(audio):
|
@@ -36,9 +21,10 @@ demo = gr.Interface(
|
|
36 |
fn=transcribe, # The function to be called for transcription
|
37 |
inputs=gr.Audio(source="microphone", type="filepath", label="Speak into the microphone"), # Input audio
|
38 |
outputs=gr.Textbox(label="Transcription"), # Output transcription
|
39 |
-
title="Whisper Speech-to-Text
|
40 |
-
description="Record audio using your microphone and get a transcription using the Whisper model
|
41 |
)
|
42 |
|
43 |
# Launch the Gradio interface
|
44 |
demo.launch()
|
|
|
|
1 |
|
|
|
|
|
2 |
import whisper
|
3 |
+
import gradio as gr
|
|
|
4 |
|
5 |
+
# Force the model to run on CPU
|
6 |
+
device = "cpu"
|
7 |
+
print("Running on CPU")
|
8 |
|
9 |
+
# Load the Whisper model on CPU
|
10 |
model_name = "tiny" # Change to "base", "small", etc., as needed
|
11 |
+
whisper_model = whisper.load_model(model_name, device=device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Define the transcription function
|
14 |
def transcribe(audio):
|
|
|
21 |
fn=transcribe, # The function to be called for transcription
|
22 |
inputs=gr.Audio(source="microphone", type="filepath", label="Speak into the microphone"), # Input audio
|
23 |
outputs=gr.Textbox(label="Transcription"), # Output transcription
|
24 |
+
title="Whisper Speech-to-Text", # Title of the interface
|
25 |
+
description="Record audio using your microphone and get a transcription using the Whisper model."
|
26 |
)
|
27 |
|
28 |
# Launch the Gradio interface
|
29 |
demo.launch()
|
30 |
+
|