Added markdown builder (codex)
This commit is contained in:
27
main.py
27
main.py
@@ -16,6 +16,7 @@ from asr_filter import AsrFilter, AsrFilterResult
|
||||
from asr_eventizer import AsrEventizer
|
||||
from structure_builder import Structure, StructureBuilder
|
||||
from structure_refiner import StructureRefiner
|
||||
from markdown_builder import MarkdownBuilder
|
||||
from windowizer import Windowizer
|
||||
|
||||
from agent import Agent
|
||||
@@ -272,10 +273,23 @@ def on_structure_refiner(current_step: Step, input_data: dict | None) -> tuple[S
|
||||
result = refiner.refine(Structure(**input_data))
|
||||
return (Step.MARKDOWN_BUILDER, result.model_dump(mode="json"))
|
||||
|
||||
def on_markdown_builder(current_step: Step, input_data: dict | None) -> tuple[Step | None, str | None]:
|
||||
if os.path.isfile(WORKFLOW_DATA[current_step][0]):
|
||||
logging.info("Skipping Markdown builder")
|
||||
return (None, None)
|
||||
if input_data is None:
|
||||
logging.error("Can't build Markdown without input_data")
|
||||
return (None, None)
|
||||
with open("events.json", "rb") as f:
|
||||
timeline = Timeline(**json.load(f))
|
||||
logging.info("Building Markdown...")
|
||||
builder = MarkdownBuilder(timeline)
|
||||
return (None, builder.build(Structure(**input_data)))
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
WORKFLOW_DATA: dict[Step, tuple[str, Callable[[Step, dict | None], tuple[Step | None, dict | None]] | None]] = {
|
||||
WORKFLOW_DATA: dict[Step, tuple[str, Callable[[Step, dict | None], tuple[Step | None, dict | str | None]] | None]] = {
|
||||
Step.MEDIA_SEPARATION: ("audio.mp3", on_media_separation),
|
||||
Step.VOICE_RECOGNITION: ("asr_raw.json", on_voice_recognition),
|
||||
Step.ASR_FILTER: ("asr.json", on_asr_filter),
|
||||
@@ -284,7 +298,7 @@ WORKFLOW_DATA: dict[Step, tuple[str, Callable[[Step, dict | None], tuple[Step |
|
||||
Step.REFERENCE_RESOLVER: ("events.json", on_reference_resolver),
|
||||
Step.STRUCTURE_BUILDER: ("structure.json", on_structure_builder),
|
||||
Step.STRUCTURE_REFINER: ("structure_refined.json", on_structure_refiner),
|
||||
Step.MARKDOWN_BUILDER: ("output.md", None)
|
||||
Step.MARKDOWN_BUILDER: ("output.md", on_markdown_builder)
|
||||
}
|
||||
"""Information about workflow.
|
||||
|
||||
@@ -314,9 +328,12 @@ def main() -> None:
|
||||
logging.info(f"Executing step {step_to_do}")
|
||||
step_to_do, ret = func(step_to_do, intermediate_result)
|
||||
if ret is not None:
|
||||
intermediate_result = ret
|
||||
with open(output_file_path, "w") as f:
|
||||
json.dump(ret, f, ensure_ascii=False, indent=4)
|
||||
with open(output_file_path, "w", encoding="utf-8") as f:
|
||||
if isinstance(ret, str):
|
||||
f.write(ret)
|
||||
else:
|
||||
intermediate_result = ret
|
||||
json.dump(ret, f, ensure_ascii=False, indent=4)
|
||||
logging.info(f"Intermediate results are saved {output_file_path}")
|
||||
# final report
|
||||
logging.info(f"Workflow was interrupted at step {step_to_do}")
|
||||
|
||||
Reference in New Issue
Block a user