ItsNotSoftware commited on
Commit
f8cf3ad
·
verified ·
1 Parent(s): 840c4e3

Upload 11 files

Browse files
.gitattributes CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  ariane6_example.mp3 filter=lfs diff=lfs merge=lfs -text
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  ariane6_example.mp3 filter=lfs diff=lfs merge=lfs -text
37
+ 26.wav filter=lfs diff=lfs merge=lfs -text
26.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:09a2d84379a713d2517638b6d188a9493221b863339a8de2b06a9b7baa9de866
3
+ size 14582680
app.py CHANGED
@@ -1,22 +1,68 @@
1
  import gradio as gr
2
- import whisper
 
 
 
3
 
4
- MODEL = whisper.load_model("small.en")
 
 
 
 
 
5
 
 
 
 
 
 
6
 
7
- def transcribe(audio):
8
- result = MODEL.transcribe(audio)
9
 
10
- try:
11
- return result["text"]
12
- except:
13
- return ""
14
 
 
 
 
15
 
16
- examples = [["apollo11_example.mp3"], ["ariane6_example.mp3"]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  ui = gr.Interface(
19
- fn=transcribe,
20
  inputs=gr.Audio(
21
  sources=["microphone", "upload"],
22
  type="filepath",
@@ -26,12 +72,12 @@ ui = gr.Interface(
26
  label="Transcription",
27
  placeholder="The transcribed text will appear here...",
28
  ),
29
- title="ECHO",
30
  description="""
31
- This is a demo of the transcription capabilities of "ECHO". This could be adapded to run real-time transcription on a live audio stream like ISS communications.
32
 
33
  ### How to use:
34
- 1. **Record or Upload**: Click on the microphone icon 🎙️ to record audio, usign your microphone, or click on the upload button ⬆️ to upload an audio file.
35
  You can also use the **Examples** provided below, as inputs, by clicking on them.
36
  2. **Click Submit**: Clicking the submit button will transcribe the audio.
37
  3. **Read the Transcription**: The transcribed text will appear in the text box below the audio input section.
@@ -39,4 +85,4 @@ ui = gr.Interface(
39
  examples=examples,
40
  )
41
 
42
- ui.launch()
 
1
  import gradio as gr
2
+ import torch
3
+ from transformers import WhisperProcessor, WhisperForConditionalGeneration
4
+ from peft import PeftModel
5
+ import torchaudio
6
 
7
+ # Constants
8
+ MODEL = "openai/whisper-small.en"
9
+ ADAPTER_DIR = "./adapter"
10
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
11
+ SAMPLE_RATE = 16000
12
+ CHUNK_LENGTH = 30 # Length of each audio chunk in seconds
13
 
14
+ # Load processor and model
15
+ processor = WhisperProcessor.from_pretrained(MODEL)
16
+ base_model = WhisperForConditionalGeneration.from_pretrained(MODEL)
17
+ finetuned_model = PeftModel.from_pretrained(base_model, ADAPTER_DIR)
18
+ finetuned_model = finetuned_model.merge_and_unload().to(DEVICE)
19
 
 
 
20
 
21
+ def load_audio(audio_path: str):
22
+ """Load and preprocess the audio file."""
23
+ speech_array, sampling_rate = torchaudio.load(audio_path)
 
24
 
25
+ # Convert stereo to mono by averaging the two channels
26
+ if speech_array.shape[0] > 1:
27
+ speech_array = torch.mean(speech_array, dim=0, keepdim=True)
28
 
29
+ # Resample to the model's required sample rate
30
+ if sampling_rate != SAMPLE_RATE:
31
+ resampler = torchaudio.transforms.Resample(sampling_rate, SAMPLE_RATE)
32
+ speech_array = resampler(speech_array)
33
+
34
+ return speech_array.squeeze().numpy()
35
+
36
+
37
+ def chunk_audio(audio, chunk_length=CHUNK_LENGTH):
38
+ """Split the audio into chunks of specified length in seconds."""
39
+ chunk_samples = chunk_length * SAMPLE_RATE
40
+ return [audio[i : i + chunk_samples] for i in range(0, len(audio), chunk_samples)]
41
+
42
+
43
+ def transcribe_chunk(chunk):
44
+ """Transcribe a single audio chunk."""
45
+ inputs = processor(chunk, sampling_rate=SAMPLE_RATE, return_tensors="pt")
46
+ input_features = inputs.input_features.to(DEVICE)
47
+
48
+ with torch.no_grad():
49
+ predicted_ids = finetuned_model.generate(input_features)
50
+
51
+ return processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
52
+
53
+
54
+ def transcribe_audio(audio_path: str) -> str:
55
+ """Transcribe the given audio file using the specified Whisper model."""
56
+ audio = load_audio(audio_path)
57
+ audio_chunks = chunk_audio(audio)
58
+ transcriptions = [transcribe_chunk(chunk) for chunk in audio_chunks]
59
+ return " ".join(transcriptions)
60
+
61
+
62
+ examples = [["apollo11_example.mp3"], ["mock_operator_example.wav"]]
63
 
64
  ui = gr.Interface(
65
+ fn=transcribe_audio,
66
  inputs=gr.Audio(
67
  sources=["microphone", "upload"],
68
  type="filepath",
 
72
  label="Transcription",
73
  placeholder="The transcribed text will appear here...",
74
  ),
75
+ title="ECHO V0.1",
76
  description="""
77
+ This is a demo of the transcription capabilities of "ECHO". This could be adapted to run real-time transcription on a live audio stream like ISS communications.
78
 
79
  ### How to use:
80
+ 1. **Record or Upload**: Click on the microphone icon 🎙️ to record audio, using your microphone, or click on the upload button ⬆️ to upload an audio file.
81
  You can also use the **Examples** provided below, as inputs, by clicking on them.
82
  2. **Click Submit**: Clicking the submit button will transcribe the audio.
83
  3. **Read the Transcription**: The transcribed text will appear in the text box below the audio input section.
 
85
  examples=examples,
86
  )
87
 
88
+ ui.launch(share=False)
checkpoint-60/README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: openai/whisper-small.en
3
+ library_name: peft
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
200
+ ### Framework versions
201
+
202
+ - PEFT 0.11.1
checkpoint-60/adapter_config.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": {
4
+ "base_model_class": "WhisperForConditionalGeneration",
5
+ "parent_library": "transformers.models.whisper.modeling_whisper"
6
+ },
7
+ "base_model_name_or_path": "openai/whisper-small.en",
8
+ "bias": "none",
9
+ "fan_in_fan_out": false,
10
+ "inference_mode": true,
11
+ "init_lora_weights": true,
12
+ "layer_replication": null,
13
+ "layers_pattern": null,
14
+ "layers_to_transform": null,
15
+ "loftq_config": {},
16
+ "lora_alpha": 64,
17
+ "lora_dropout": 0.05,
18
+ "megatron_config": null,
19
+ "megatron_core": "megatron.core",
20
+ "modules_to_save": null,
21
+ "peft_type": "LORA",
22
+ "r": 32,
23
+ "rank_pattern": {},
24
+ "revision": null,
25
+ "target_modules": [
26
+ "q_proj",
27
+ "v_proj"
28
+ ],
29
+ "task_type": null,
30
+ "use_dora": false,
31
+ "use_rslora": false
32
+ }
checkpoint-60/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b15e3353f37af4d1d7ea1e44c080cec9113f64cb7c6a493493c4c58d2bc1727
3
+ size 14176064
checkpoint-60/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bbd9b9489f49bc8b005817941551fb0de48c78b22311090f390a56d914770267
3
+ size 28432570
checkpoint-60/preprocessor_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "chunk_length": 30,
3
+ "feature_extractor_type": "WhisperFeatureExtractor",
4
+ "feature_size": 80,
5
+ "hop_length": 160,
6
+ "n_fft": 400,
7
+ "n_samples": 480000,
8
+ "nb_max_frames": 3000,
9
+ "padding_side": "right",
10
+ "padding_value": 0.0,
11
+ "processor_class": "WhisperProcessor",
12
+ "return_attention_mask": false,
13
+ "sampling_rate": 16000
14
+ }
checkpoint-60/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70af4d9ff66efb9b200a49233a3dcb06212cd5c42860c820af8b3b0f975f616d
3
+ size 14244
checkpoint-60/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6574cff4022f3e678230ab559d2aabe9a67f1acea6716a875a3ad2c85bea47c
3
+ size 1064
checkpoint-60/trainer_state.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 5.0,
5
+ "eval_steps": 500,
6
+ "global_step": 60,
7
+ "is_hyper_param_search": false,
8
+ "is_local_process_zero": true,
9
+ "is_world_process_zero": true,
10
+ "log_history": [
11
+ {
12
+ "epoch": 0,
13
+ "eval_loss": 2.356511354446411,
14
+ "eval_runtime": 27.7264,
15
+ "eval_samples_per_second": 15.4,
16
+ "eval_steps_per_second": 0.252,
17
+ "eval_wer": 22.12566844919786,
18
+ "step": 0
19
+ },
20
+ {
21
+ "epoch": 1.0,
22
+ "grad_norm": 0.6522291302680969,
23
+ "learning_rate": 0.0008,
24
+ "loss": 0.8625,
25
+ "step": 12
26
+ },
27
+ {
28
+ "epoch": 1.0,
29
+ "eval_loss": 0.45175907015800476,
30
+ "eval_runtime": 27.2705,
31
+ "eval_samples_per_second": 15.658,
32
+ "eval_steps_per_second": 0.257,
33
+ "eval_wer": 17.290552584670234,
34
+ "step": 12
35
+ },
36
+ {
37
+ "epoch": 2.0,
38
+ "grad_norm": 0.39275336265563965,
39
+ "learning_rate": 0.0006,
40
+ "loss": 0.2741,
41
+ "step": 24
42
+ },
43
+ {
44
+ "epoch": 2.0,
45
+ "eval_loss": 0.4212001860141754,
46
+ "eval_runtime": 27.8396,
47
+ "eval_samples_per_second": 15.338,
48
+ "eval_steps_per_second": 0.251,
49
+ "eval_wer": 18.137254901960784,
50
+ "step": 24
51
+ },
52
+ {
53
+ "epoch": 3.0,
54
+ "grad_norm": 0.35100314021110535,
55
+ "learning_rate": 0.0004,
56
+ "loss": 0.1835,
57
+ "step": 36
58
+ },
59
+ {
60
+ "epoch": 3.0,
61
+ "eval_loss": 0.4116327464580536,
62
+ "eval_runtime": 27.3845,
63
+ "eval_samples_per_second": 15.593,
64
+ "eval_steps_per_second": 0.256,
65
+ "eval_wer": 17.446524064171122,
66
+ "step": 36
67
+ },
68
+ {
69
+ "epoch": 4.0,
70
+ "grad_norm": 0.23920069634914398,
71
+ "learning_rate": 0.0002,
72
+ "loss": 0.1354,
73
+ "step": 48
74
+ },
75
+ {
76
+ "epoch": 4.0,
77
+ "eval_loss": 0.41445085406303406,
78
+ "eval_runtime": 27.6194,
79
+ "eval_samples_per_second": 15.46,
80
+ "eval_steps_per_second": 0.253,
81
+ "eval_wer": 18.070409982174688,
82
+ "step": 48
83
+ },
84
+ {
85
+ "epoch": 5.0,
86
+ "grad_norm": 0.18301299214363098,
87
+ "learning_rate": 0.0,
88
+ "loss": 0.1074,
89
+ "step": 60
90
+ },
91
+ {
92
+ "epoch": 5.0,
93
+ "eval_loss": 0.41686326265335083,
94
+ "eval_runtime": 27.6106,
95
+ "eval_samples_per_second": 15.465,
96
+ "eval_steps_per_second": 0.254,
97
+ "eval_wer": 17.713903743315505,
98
+ "step": 60
99
+ }
100
+ ],
101
+ "logging_steps": 500,
102
+ "max_steps": 60,
103
+ "num_input_tokens_seen": 0,
104
+ "num_train_epochs": 5,
105
+ "save_steps": 500,
106
+ "stateful_callbacks": {
107
+ "TrainerControl": {
108
+ "args": {
109
+ "should_epoch_stop": false,
110
+ "should_evaluate": false,
111
+ "should_log": false,
112
+ "should_save": true,
113
+ "should_training_stop": true
114
+ },
115
+ "attributes": {}
116
+ }
117
+ },
118
+ "total_flos": 1.1145212153856e+18,
119
+ "train_batch_size": 64,
120
+ "trial_name": null,
121
+ "trial_params": null
122
+ }
checkpoint-60/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2adcdff3799c0e56a840f3713150b8368783a95ba20e632256f7506c42c60001
3
+ size 5240