Yehor Smoliakov
commited on
Commit
·
774c0b8
1
Parent(s):
47fd9c8
ruffed
Browse files- .gitignore +3 -1
- app.py +13 -10
.gitignore
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
.idea/
|
| 2 |
.venv/
|
| 3 |
-
|
|
|
|
|
|
|
|
|
| 1 |
.idea/
|
| 2 |
.venv/
|
| 3 |
+
.ruff_cache/
|
| 4 |
+
|
| 5 |
+
flagged/
|
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import sys
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
import torch
|
| 5 |
-
import torchaudio
|
| 6 |
import librosa
|
| 7 |
|
| 8 |
import gradio as gr
|
|
@@ -21,7 +20,9 @@ concurrency_limit = 1
|
|
| 21 |
use_torch_compile = False
|
| 22 |
|
| 23 |
# Load the model
|
| 24 |
-
asr_model = AutoModelForCTC.from_pretrained(model_name, torch_dtype=torch_dtype).to(
|
|
|
|
|
|
|
| 25 |
processor = Wav2Vec2BertProcessor.from_pretrained(model_name)
|
| 26 |
|
| 27 |
if use_torch_compile:
|
|
@@ -37,7 +38,7 @@ examples = [
|
|
| 37 |
"example_6.wav",
|
| 38 |
]
|
| 39 |
|
| 40 |
-
examples_table =
|
| 41 |
| File | Text |
|
| 42 |
| ------------- | ------------- |
|
| 43 |
| `example_1.wav` | тема про яку не люблять говорити офіційні джерела у генштабі і міноборони це хімічна зброя окупанти вже тривалий час використовують хімічну зброю заборонену |
|
|
@@ -46,10 +47,10 @@ examples_table = '''
|
|
| 46 |
| `example_4.wav` | використовує на фронті все що має і хімічна зброя не нийняток тож з чим маємо справу розбиралася марія моганисян |
|
| 47 |
| `example_5.wav` | двох тисяч випадків застосування росіянами боєприпасів споряджених небезпечними хімічними речовинами |
|
| 48 |
| `example_6.wav` | на всі писані норми марія моганисян олександр моторний спецкор марафон єдині новини |
|
| 49 |
-
|
| 50 |
|
| 51 |
# https://www.tablesgenerator.com/markdown_tables
|
| 52 |
-
authors_table =
|
| 53 |
## Authors
|
| 54 |
|
| 55 |
Follow them in social networks and **contact** if you need any help or have any questions:
|
|
@@ -61,7 +62,7 @@ Follow them in social networks and **contact** if you need any help or have any
|
|
| 61 |
| https://github.com/egorsmkv at GitHub |
|
| 62 |
| https://huggingface.co/Yehor at Hugging Face |
|
| 63 |
| or use egorsmkv@gmail.com |
|
| 64 |
-
|
| 65 |
|
| 66 |
description_head = f"""
|
| 67 |
# Speech-to-Text for Ukrainian v2
|
|
@@ -121,7 +122,9 @@ def inference(audio_path, progress=gr.Progress()):
|
|
| 121 |
|
| 122 |
duration = librosa.get_duration(path=audio_path)
|
| 123 |
if duration < min_duration:
|
| 124 |
-
raise gr.Error(
|
|
|
|
|
|
|
| 125 |
if duration > max_duration:
|
| 126 |
raise gr.Error(f"The duration of the file exceeds {max_duration} seconds.")
|
| 127 |
|
|
@@ -150,7 +153,7 @@ def inference(audio_path, progress=gr.Progress()):
|
|
| 150 |
predictions = processor.batch_decode(predicted_ids)
|
| 151 |
|
| 152 |
if not predictions:
|
| 153 |
-
predictions =
|
| 154 |
|
| 155 |
elapsed_time = round(time.time() - t0, 2)
|
| 156 |
rtf = round(elapsed_time / audio_duration, 4)
|
|
@@ -207,12 +210,12 @@ with demo:
|
|
| 207 |
|
| 208 |
with gr.Row():
|
| 209 |
gr.Examples(label="Choose an example", inputs=audio_file, examples=examples)
|
| 210 |
-
|
| 211 |
gr.Markdown(examples_table)
|
| 212 |
|
| 213 |
gr.Markdown(description_foot)
|
| 214 |
|
| 215 |
-
gr.Markdown(
|
| 216 |
with gr.Row():
|
| 217 |
gr.Markdown(tech_env)
|
| 218 |
gr.Markdown(tech_libraries)
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
import torch
|
|
|
|
| 5 |
import librosa
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 20 |
use_torch_compile = False
|
| 21 |
|
| 22 |
# Load the model
|
| 23 |
+
asr_model = AutoModelForCTC.from_pretrained(model_name, torch_dtype=torch_dtype).to(
|
| 24 |
+
device
|
| 25 |
+
)
|
| 26 |
processor = Wav2Vec2BertProcessor.from_pretrained(model_name)
|
| 27 |
|
| 28 |
if use_torch_compile:
|
|
|
|
| 38 |
"example_6.wav",
|
| 39 |
]
|
| 40 |
|
| 41 |
+
examples_table = """
|
| 42 |
| File | Text |
|
| 43 |
| ------------- | ------------- |
|
| 44 |
| `example_1.wav` | тема про яку не люблять говорити офіційні джерела у генштабі і міноборони це хімічна зброя окупанти вже тривалий час використовують хімічну зброю заборонену |
|
|
|
|
| 47 |
| `example_4.wav` | використовує на фронті все що має і хімічна зброя не нийняток тож з чим маємо справу розбиралася марія моганисян |
|
| 48 |
| `example_5.wav` | двох тисяч випадків застосування росіянами боєприпасів споряджених небезпечними хімічними речовинами |
|
| 49 |
| `example_6.wav` | на всі писані норми марія моганисян олександр моторний спецкор марафон єдині новини |
|
| 50 |
+
""".strip()
|
| 51 |
|
| 52 |
# https://www.tablesgenerator.com/markdown_tables
|
| 53 |
+
authors_table = """
|
| 54 |
## Authors
|
| 55 |
|
| 56 |
Follow them in social networks and **contact** if you need any help or have any questions:
|
|
|
|
| 62 |
| https://github.com/egorsmkv at GitHub |
|
| 63 |
| https://huggingface.co/Yehor at Hugging Face |
|
| 64 |
| or use egorsmkv@gmail.com |
|
| 65 |
+
""".strip()
|
| 66 |
|
| 67 |
description_head = f"""
|
| 68 |
# Speech-to-Text for Ukrainian v2
|
|
|
|
| 122 |
|
| 123 |
duration = librosa.get_duration(path=audio_path)
|
| 124 |
if duration < min_duration:
|
| 125 |
+
raise gr.Error(
|
| 126 |
+
f"The duration of the file is less than {min_duration} seconds, it is {round(duration, 2)} seconds."
|
| 127 |
+
)
|
| 128 |
if duration > max_duration:
|
| 129 |
raise gr.Error(f"The duration of the file exceeds {max_duration} seconds.")
|
| 130 |
|
|
|
|
| 153 |
predictions = processor.batch_decode(predicted_ids)
|
| 154 |
|
| 155 |
if not predictions:
|
| 156 |
+
predictions = "-"
|
| 157 |
|
| 158 |
elapsed_time = round(time.time() - t0, 2)
|
| 159 |
rtf = round(elapsed_time / audio_duration, 4)
|
|
|
|
| 210 |
|
| 211 |
with gr.Row():
|
| 212 |
gr.Examples(label="Choose an example", inputs=audio_file, examples=examples)
|
| 213 |
+
|
| 214 |
gr.Markdown(examples_table)
|
| 215 |
|
| 216 |
gr.Markdown(description_foot)
|
| 217 |
|
| 218 |
+
gr.Markdown("### Gradio app uses the following technologies:")
|
| 219 |
with gr.Row():
|
| 220 |
gr.Markdown(tech_env)
|
| 221 |
gr.Markdown(tech_libraries)
|