adiitya29 commited on
Commit
c17b8b3
·
0 Parent(s):

barebone setup of project structure

Browse files
.gitignore ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # Usually these files are written by a python script from a template
157
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
158
+ .idea/
159
+
160
+ # VS Code
161
+ .vscode/
162
+
163
+ # Mac OS
164
+ .DS_Store
165
+
166
+ # Models and large datasets
167
+ *.pt
168
+ *.pth
169
+ *.bin
170
+ *.h5
171
+ *.hdf5
172
+ data/*
173
+ !data/.gitkeep
174
+ models/*
175
+ !models/.gitkeep
176
+
177
+ # Histories and output transcripts
178
+ *.json
179
+ *.csv
180
+ !app/templates/*.json
README.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Multilingual Automatic Speech Recognition (ASR)
2
+
3
+ This project provides a web application to upload audio files, detect spoken language, convert speech to text, and download transcripts. It leverages pre-trained Wav2Vec models from Hugging Face and uses Gradio for the frontend interface.
4
+
5
+ ## Features
6
+ - Upload audio files
7
+ - (Optional) Detect spoken language
8
+ - Speech-to-text conversion via Hugging Face Wav2Vec
9
+ - Save and manage transcription history
10
+ - Download transcripts
11
+
12
+ ## Setup
13
+
14
+ 1. **Clone the repository** (or download the source code).
15
+ 2. **Create a virtual environment**:
16
+ ```bash
17
+ python -m venv venv
18
+ source venv/bin/activate
19
+ ```
20
+ 3. **Install dependencies**:
21
+ ```bash
22
+ pip install -r requirements.txt
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ To start the Gradio web interface, run:
28
+
29
+ ```bash
30
+ python app.py
31
+ ```
32
+
33
+ Open the local URL provided in the terminal in your browser.
34
+
35
+ ## Project Structure
36
+
37
+ - `app.py`: Main entry point for the Gradio interface.
38
+ - `app/`: Module containing logic for audio processing, ASR inference, language detection, and history management.
39
+ - `data/`: Folder to hold sample audio files and exported histories.
40
+ - `notebooks/`: Jupyter notebooks for experiments and fine-tuning.
41
+ - `tests/`: Unit testing suite.
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from app.asr_model import load_model, transcribe_audio
3
+ from app.language_detection import detect_language
4
+ from app.history import save_to_history, export_history
5
+
6
+ def process_audio(audio_path):
7
+ if audio_path is None:
8
+ return "No audio uploaded.", "Unknown"
9
+
10
+ # Optional: Detect Language
11
+ lang = detect_language(audio_path)
12
+
13
+ # Transcribe Speech
14
+ transcript = transcribe_audio(audio_path)
15
+
16
+ # Save History
17
+ save_to_history(audio_path, transcript, lang)
18
+
19
+ return transcript, lang
20
+
21
+ def create_ui():
22
+ with gr.Blocks(title="Multilingual ASR") as demo:
23
+ gr.Markdown("# Multilingual Automatic Speech Recognition")
24
+ gr.Markdown("Upload an audio file to get a text transcription using Wav2Vec.")
25
+
26
+ with gr.Row():
27
+ with gr.Column():
28
+ audio_input = gr.Audio(type="filepath", label="Upload Audio")
29
+ transcribe_btn = gr.Button("Transcribe")
30
+
31
+ with gr.Column():
32
+ lang_output = gr.Textbox(label="Detected Language")
33
+ transcript_output = gr.Textbox(label="Transcription", lines=10)
34
+ download_btn = gr.File(label="Download Transcript (Coming Soon)")
35
+
36
+ transcribe_btn.click(
37
+ fn=process_audio,
38
+ inputs=audio_input,
39
+ outputs=[transcript_output, lang_output]
40
+ )
41
+
42
+ return demo
43
+
44
+ if __name__ == "__main__":
45
+ # Pre-load model on start
46
+ print("Loading model...")
47
+ load_model()
48
+ print("Model loaded. Starting UI...")
49
+
50
+ demo = create_ui()
51
+ demo.launch()
app/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # Init file to make app a package
app/asr_model.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This module handles the loading and inferencing of the Wav2Vec model
2
+
3
+ def load_model():
4
+ """
5
+ Loads the Hugging Face Wav2Vec model and processor.
6
+ For Apple Silicon, we can utilize MPS (Metal Performance Shaders) later.
7
+ """
8
+ pass
9
+
10
+ def transcribe_audio(audio_filepath: str) -> str:
11
+ """
12
+ Takes an audio filepath, processes it, and runs it through the Wav2Vec model
13
+ to return a text transcription.
14
+ """
15
+ return "This is a placeholder transcription. Model integration is pending."
app/audio_processing.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # This module handles audio preprocessing using libraries like librosa
2
+
3
+ def load_and_resample(audio_filepath: str, target_sr: int = 16000):
4
+ """
5
+ Loads an audio file and resamples it to the target sample rate (default 16kHz for Wav2Vec).
6
+ """
7
+ pass
app/history.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This module manages saving transcriptions to history and exporting them
2
+
3
+ def save_to_history(audio_filepath: str, transcript: str, language: str):
4
+ """
5
+ Saves the transcription data to a local JSON or CSV file in the data/ directory.
6
+ """
7
+ pass
8
+
9
+ def export_history(format: str = "csv"):
10
+ """
11
+ Exports the saved history into a downloadable format.
12
+ """
13
+ pass
app/language_detection.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # This module handles language detection logic
2
+
3
+ def detect_language(audio_filepath: str) -> str:
4
+ """
5
+ Optional feature to detect the spoken language in the audio file.
6
+ Could use a separate small classification model or an API.
7
+ """
8
+ return "English (Placeholder)"
requirements.txt ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Core Deep Learning
2
+ torch>=2.0.0
3
+ torchaudio>=2.0.0
4
+ transformers>=4.30.0
5
+
6
+ # Audio Processing
7
+ librosa>=0.10.0
8
+ soundfile>=0.12.1
9
+
10
+ # Web Interface
11
+ gradio>=4.0.0
12
+
13
+ # Language Detection (Optional)
14
+ langdetect>=1.0.9
15
+ fasttext>=0.9.2 # Alternative for lang detect
16
+
17
+ # Utilities
18
+ numpy>=1.24.0
19
+ pandas>=2.0.0
20
+ python-dotenv>=1.0.0