Spaces:
Runtime error
Runtime error
github-actions[bot]
commited on
Commit
·
c318bd7
1
Parent(s):
8370c97
Sync with https://github.com/mozilla-ai/speech-to-text-finetune
Browse files
app.py
CHANGED
|
@@ -29,20 +29,26 @@ def _load_local_model(model_dir: str) -> Pipeline:
|
|
| 29 |
feature_extractor = WhisperFeatureExtractor.from_pretrained(model_dir)
|
| 30 |
model = WhisperForConditionalGeneration.from_pretrained(model_dir)
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
def _load_hf_model(model_repo_id: str) -> Pipeline:
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
@spaces.GPU(duration=30)
|
|
@@ -61,6 +67,9 @@ def transcribe(
|
|
| 61 |
pipe = _load_local_model(local_model_id)
|
| 62 |
else:
|
| 63 |
return "️️⚠️ Please select or fill at least and only one of the options above"
|
|
|
|
|
|
|
|
|
|
| 64 |
text = pipe(audio)["text"]
|
| 65 |
return text
|
| 66 |
|
|
@@ -69,10 +78,9 @@ def setup_gradio_demo():
|
|
| 69 |
with gr.Blocks() as demo:
|
| 70 |
gr.Markdown(
|
| 71 |
""" # 🗣️ Speech-to-Text Transcription
|
| 72 |
-
### 1. Select which model to
|
| 73 |
-
### 2.
|
| 74 |
-
### 3.
|
| 75 |
-
### 4. Click Transcribe to see the transcription generated by the model.
|
| 76 |
"""
|
| 77 |
)
|
| 78 |
### Model selection ###
|
|
|
|
| 29 |
feature_extractor = WhisperFeatureExtractor.from_pretrained(model_dir)
|
| 30 |
model = WhisperForConditionalGeneration.from_pretrained(model_dir)
|
| 31 |
|
| 32 |
+
try:
|
| 33 |
+
return pipeline(
|
| 34 |
+
task="automatic-speech-recognition",
|
| 35 |
+
model=model,
|
| 36 |
+
processor=processor,
|
| 37 |
+
tokenizer=tokenizer,
|
| 38 |
+
feature_extractor=feature_extractor,
|
| 39 |
+
)
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return str(e)
|
| 42 |
|
| 43 |
|
| 44 |
def _load_hf_model(model_repo_id: str) -> Pipeline:
|
| 45 |
+
try:
|
| 46 |
+
return pipeline(
|
| 47 |
+
"automatic-speech-recognition",
|
| 48 |
+
model=model_repo_id,
|
| 49 |
+
)
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return str(e)
|
| 52 |
|
| 53 |
|
| 54 |
@spaces.GPU(duration=30)
|
|
|
|
| 67 |
pipe = _load_local_model(local_model_id)
|
| 68 |
else:
|
| 69 |
return "️️⚠️ Please select or fill at least and only one of the options above"
|
| 70 |
+
if isinstance(pipe, str):
|
| 71 |
+
# Exception raised
|
| 72 |
+
return pipe
|
| 73 |
text = pipe(audio)["text"]
|
| 74 |
return text
|
| 75 |
|
|
|
|
| 78 |
with gr.Blocks() as demo:
|
| 79 |
gr.Markdown(
|
| 80 |
""" # 🗣️ Speech-to-Text Transcription
|
| 81 |
+
### 1. Select which model to use from one of the options below.
|
| 82 |
+
### 2. Record a message or upload an audio file.
|
| 83 |
+
### 3. Click Transcribe to see the transcription generated by the model.
|
|
|
|
| 84 |
"""
|
| 85 |
)
|
| 86 |
### Model selection ###
|