mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
* initial * add LLM features * update LLM logic * update llm functions: change control flow * add generation config * update return types * update processors and tests * update rtc_offer * revert new title processor change * fix unit tests * add comments and fix HTTP 500 * adjust prompt * test with reflector app * revert new event for final title * update * move onus onto processors * move onus onto processors * stash * add provision for gen config * dynamically pack the LLM input using context length * tune final summary params * update consolidated class structures * update consolidated class structures * update precommit * add broadcast processors * working baseline * Organize LLMParams * minor fixes * minor fixes * minor fixes * fix unit tests * fix unit tests * fix unit tests * update tests * update tests * edit pipeline response events * update summary return types * configure tests * alembic db migration * change LLM response flow * edit main llm functions * edit main llm functions * change llm name and gen cf * Update transcript_topic_detector.py * PR review comments * checkpoint before db event migration * update DB migration of past events * update DB migration of past events * edit LLM classes * Delete unwanted file * remove List typing * remove List typing * update oobabooga API call * topic enhancements * update UI event handling * move ensure_casing to llm base * update tests * update tests
106 lines
3.1 KiB
Python
106 lines
3.1 KiB
Python
import asyncio
|
|
|
|
import av
|
|
|
|
from reflector.logger import logger
|
|
from reflector.processors import (
|
|
AudioChunkerProcessor,
|
|
AudioMergeProcessor,
|
|
AudioTranscriptAutoProcessor,
|
|
Pipeline,
|
|
PipelineEvent,
|
|
TranscriptFinalLongSummaryProcessor,
|
|
TranscriptFinalShortSummaryProcessor,
|
|
TranscriptFinalTitleProcessor,
|
|
TranscriptLinerProcessor,
|
|
TranscriptTopicDetectorProcessor,
|
|
)
|
|
from reflector.processors.base import BroadcastProcessor
|
|
|
|
|
|
async def process_audio_file(
|
|
filename,
|
|
event_callback,
|
|
only_transcript=False,
|
|
source_language="en",
|
|
target_language="en",
|
|
):
|
|
# build pipeline for audio processing
|
|
processors = [
|
|
AudioChunkerProcessor(),
|
|
AudioMergeProcessor(),
|
|
AudioTranscriptAutoProcessor.as_threaded(),
|
|
TranscriptLinerProcessor(),
|
|
]
|
|
if not only_transcript:
|
|
processors += [
|
|
TranscriptTopicDetectorProcessor.as_threaded(),
|
|
BroadcastProcessor(
|
|
processors=[
|
|
TranscriptFinalTitleProcessor.as_threaded(),
|
|
TranscriptFinalLongSummaryProcessor.as_threaded(),
|
|
TranscriptFinalShortSummaryProcessor.as_threaded(),
|
|
],
|
|
),
|
|
]
|
|
|
|
# transcription output
|
|
pipeline = Pipeline(*processors)
|
|
pipeline.set_pref("audio:source_language", source_language)
|
|
pipeline.set_pref("audio:target_language", target_language)
|
|
pipeline.describe()
|
|
pipeline.on(event_callback)
|
|
|
|
# start processing audio
|
|
logger.info(f"Opening {filename}")
|
|
container = av.open(filename)
|
|
try:
|
|
logger.info("Start pushing audio into the pipeline")
|
|
for frame in container.decode(audio=0):
|
|
await pipeline.push(frame)
|
|
finally:
|
|
logger.info("Flushing the pipeline")
|
|
await pipeline.flush()
|
|
|
|
logger.info("All done !")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("source", help="Source file (mp3, wav, mp4...)")
|
|
parser.add_argument("--only-transcript", "-t", action="store_true")
|
|
parser.add_argument("--source-language", default="en")
|
|
parser.add_argument("--target-language", default="en")
|
|
parser.add_argument("--output", "-o", help="Output file (output.jsonl)")
|
|
args = parser.parse_args()
|
|
|
|
output_fd = None
|
|
if args.output:
|
|
output_fd = open(args.output, "w")
|
|
|
|
async def event_callback(event: PipelineEvent):
|
|
processor = event.processor
|
|
# ignore some processor
|
|
if processor in ("AudioChunkerProcessor", "AudioMergeProcessor"):
|
|
return
|
|
logger.info(f"Event: {event}")
|
|
if output_fd:
|
|
output_fd.write(event.model_dump_json())
|
|
output_fd.write("\n")
|
|
|
|
asyncio.run(
|
|
process_audio_file(
|
|
args.source,
|
|
event_callback,
|
|
only_transcript=args.only_transcript,
|
|
source_language=args.source_language,
|
|
target_language=args.target_language,
|
|
)
|
|
)
|
|
|
|
if output_fd:
|
|
output_fd.close()
|
|
logger.info(f"Output written to {args.output}")
|