Feature request: added huggingface functionality checking for token
This commit is contained in:
+4
-1
@@ -10,4 +10,7 @@ __pycache__/
|
|||||||
.venv
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
ENV/
|
||||||
|
|
||||||
|
# Large files
|
||||||
|
data/models # local storage of transcriber models
|
||||||
@@ -4,10 +4,61 @@
|
|||||||
|
|
||||||
Transcriber code
|
Transcriber code
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Before running this script, make sure to install the necessary python packages using the following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running the script
|
||||||
|
|
||||||
|
To generate transcripts create a new job with your specifications (see jobs section below).
|
||||||
|
<br/>
|
||||||
|
If you need to download the transcriber model (not saved in `data/models`yet) set your huggingface token:
|
||||||
|
|
||||||
|
On Linux/Mac:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export HF_TOKEN="your-token-here"
|
||||||
|
```
|
||||||
|
|
||||||
|
On Windows (Command prompt):
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
set HF_TOKEN="your-token-here"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then run the following command to generate your transcript:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
main.py --job {name}
|
||||||
|
```
|
||||||
|
|
||||||
|
where name is the name of your job.
|
||||||
|
|
||||||
|
## Jobs
|
||||||
|
|
||||||
|
Jobs specify tasks for transcript creation. A job contains the following information.
|
||||||
|
|
||||||
|
- `name`: string: The name of the job
|
||||||
|
- `source`: List[string]: The sources of the videos (paths, YouTube links, TibAV links)
|
||||||
|
- `modelpath`: Optional[string]: The path to the model if already saved locally (will be downloaded temporarily if not)
|
||||||
|
- `language`: Optional[string]: The language of the video (If not specified employs auto-detection)
|
||||||
|
|
||||||
## to-do
|
## to-do
|
||||||
|
|
||||||
- seperate data production form code
|
- seperate data production form code
|
||||||
- seperate huggingface (hf) token out
|
- remember to accept the conditions on diarization if you use huggingface
|
||||||
|
- do a config json
|
||||||
|
- do option to have models already stored and point to them (is this necessary?)
|
||||||
|
- also for single language models
|
||||||
|
- check warnings
|
||||||
|
- downloader for tib-av
|
||||||
|
- more optional setting
|
||||||
|
|
||||||
|
## Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
project_root/
|
project_root/
|
||||||
@@ -23,6 +74,7 @@ project_root/
|
|||||||
│ └── test_transcript_generator.py
|
│ └── test_transcript_generator.py
|
||||||
├── data/
|
├── data/
|
||||||
│ ├── audio/ # downloaded mp4 and output wav files
|
│ ├── audio/ # downloaded mp4 and output wav files
|
||||||
|
│ ├── models/ # models used for transcripts (are ignored by git and not necessarily)
|
||||||
│ └── transcripts/ # JSON and text transcript files
|
│ └── transcripts/ # JSON and text transcript files
|
||||||
└── README.md
|
└── README.md
|
||||||
```
|
```
|
||||||
@@ -37,4 +89,4 @@ project_root/
|
|||||||
- **tests/**: This directory contains all your test scripts corresponding to your source files.
|
- **tests/**: This directory contains all your test scripts corresponding to your source files.
|
||||||
|
|
||||||
- **data/**: This directory contains all the data needed for your code. For simplicity, I categorize the files into
|
- **data/**: This directory contains all the data needed for your code. For simplicity, I categorize the files into
|
||||||
separate directories for audio and transcript files.
|
separate directories for audio, model and transcript files.
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
from src.transcript_generator import TranscriptGenerator
|
from src.transcript_generator import TranscriptGenerator
|
||||||
|
|
||||||
|
|
||||||
@@ -7,6 +9,11 @@ def main():
|
|||||||
'https://www.youtube.com/watch?v=BVVo1BaL6JA'
|
'https://www.youtube.com/watch?v=BVVo1BaL6JA'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
hf_token = os.environ.get('HF_TOKEN')
|
||||||
|
if not hf_token:
|
||||||
|
hf_token = input("Please enter your HF_TOKEN: ")
|
||||||
|
os.environ['HF_TOKEN'] = hf_token
|
||||||
|
|
||||||
transcript_generator = TranscriptGenerator()
|
transcript_generator = TranscriptGenerator()
|
||||||
transcript_generator.generate(input_sources)
|
transcript_generator.generate(input_sources)
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
import gc
|
import gc
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import whisperx
|
import whisperx
|
||||||
@@ -30,6 +31,7 @@ class Transcriber:
|
|||||||
logger.exception("Failed to initialize models: %s", e)
|
logger.exception("Failed to initialize models: %s", e)
|
||||||
raise
|
raise
|
||||||
self.transcript_output = None
|
self.transcript_output = None
|
||||||
|
self.hf_token = os.environ.get('HF_TOKEN')
|
||||||
|
|
||||||
def transcribe(self, wav_filename: str, batch_size: int = 16) -> dict:
|
def transcribe(self, wav_filename: str, batch_size: int = 16) -> dict:
|
||||||
"""
|
"""
|
||||||
@@ -53,7 +55,7 @@ class Transcriber:
|
|||||||
self._clear_memory()
|
self._clear_memory()
|
||||||
|
|
||||||
# Run Diarization
|
# Run Diarization
|
||||||
diarize_model = whisperx.DiarizationPipeline(use_auth_token='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',
|
diarize_model = whisperx.DiarizationPipeline(use_auth_token=self.hf_token,
|
||||||
device=self.device)
|
device=self.device)
|
||||||
diarize_segments = diarize_model(audio)
|
diarize_segments = diarize_model(audio)
|
||||||
result = whisperx.assign_word_speakers(diarize_segments, result)
|
result = whisperx.assign_word_speakers(diarize_segments, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user