From e2b5ad15b48f039c9b340b192e2088a54a4f68e3 Mon Sep 17 00:00:00 2001 From: ganders Date: Tue, 10 Oct 2023 14:17:38 +0200 Subject: [PATCH] Feature request: added json config --- README.md | 8 ++++++-- data/jobs/example_job.json | 6 ++++++ main.py | 28 ++++++++++++++++++++++------ src/transcript_generator.py | 13 +++++++------ 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 data/jobs/example_job.json diff --git a/README.md b/README.md index 5a51fcc..d7ebe41 100644 --- a/README.md +++ b/README.md @@ -52,14 +52,18 @@ Jobs specify tasks for transcript creation. A job contains the following informa - `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 a specific model should be used. - `language`: Optional[string]: The language of the video (If not specified employs auto-detection) ## to-do +### Feature: specific model + +add an opitonal model path to the json config +- `model_path`:Optional[string]: The path to a specific language model to be used (mainly for testing) + +### Other - seperate data production form code - remember to accept the conditions on models if you use huggingface -- do a config json - check warnings - downloader for tib-av - more optional setting diff --git a/data/jobs/example_job.json b/data/jobs/example_job.json new file mode 100644 index 0000000..4a27811 --- /dev/null +++ b/data/jobs/example_job.json @@ -0,0 +1,6 @@ +{ + "name": "myjob1", + "source": [ + "https://www.youtube.com/watch?v=BVVo1BaL6JA" + ] +} \ No newline at end of file diff --git a/main.py b/main.py index 2c5c6f1..4f91315 100644 --- a/main.py +++ b/main.py @@ -1,20 +1,36 @@ import os +import json +import argparse from src.transcript_generator import TranscriptGenerator def main(): - # input could be a YouTube link or a local file - input_sources = ["https://www.youtube.com/watch?v=BVVo1BaL6JA"] + # Create a parser + parser = argparse.ArgumentParser(description='Transcript Generator for Videos') + # Add the arguments + parser.add_argument('--job', type=str, help='The name of the job', required=True) + + # Parse the arguments + args = parser.parse_args() + + # Load the job config + with open(f'jobs/{args.job}.json', 'r') as f: + job_config = json.load(f) + + # Check the hf_token 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.generate(input_sources) + transcript_generator = TranscriptGenerator( + name=job_config['name'], + language_code=job_config['language_code'] + ) + transcript_generator.generate(job_config['source']) -if __name__ == "__main__": - main() + if __name__ == "__main__": + main() diff --git a/src/transcript_generator.py b/src/transcript_generator.py index 51cd113..03594d3 100644 --- a/src/transcript_generator.py +++ b/src/transcript_generator.py @@ -15,9 +15,10 @@ class TranscriptGenerator: to generate transcriptions from given input sources. """ - def __init__(self): + def __init__(self, job_name, language_code="en"): self.file_manager = FileManager() - self.transcriber = Transcriber() + self.transcriber = Transcriber(language_code) + self.job_name = job_name def generate(self, input_sources: List[str]) -> None: """ @@ -29,15 +30,15 @@ class TranscriptGenerator: for i, source in enumerate(input_sources): try: if source.startswith("http"): - mp4_filename = f"audio_{i + 1}.mp4" - wav_filename = f"audio_{i + 1}.wav" + mp4_filename = f"audio_{self.job_name}_{i + 1}.mp4" + wav_filename = f"audio_{self.job_name}_{i + 1}.wav" self.file_manager.download_youtube_audio(source, mp4_filename) self.file_manager.convert_to_wav(mp4_filename, wav_filename) else: wav_filename = self.file_manager.load_local_file(source) self.transcriber.transcribe(wav_filename) - json_output_file = f"result_{i + 1}.json" - txt_output_file = f"transcripts_{i + 1}.txt" + json_output_file = f"result_{self.job_name}_{i + 1}.json" + txt_output_file = f"transcripts_{self.job_name}_{i + 1}.txt" self.transcriber.save_transcript(json_output_file, txt_output_file) except Exception as e: logger.exception(