-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·62 lines (49 loc) · 1.84 KB
/
main.py
File metadata and controls
executable file
·62 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""Single-run convenience script for AudioToolAgent."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import List, Optional
from audiotoolagent.agent import AudioToolAgent, console_stream_callback
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Run the AudioToolAgent pipeline for a single audio question",
)
parser.add_argument("--config", required=True, help="Path to the agent configuration YAML")
parser.add_argument("--audio", required=True, help="Path to the input audio file")
parser.add_argument("--question", required=True, help="Question to ask about the audio")
parser.add_argument(
"--options",
nargs="+",
help="Optional multiple-choice options. If provided, the agent will select one option.",
)
parser.add_argument(
"--output",
help="Optional path to save the JSON result (defaults to stdout only)",
)
parser.add_argument(
"--no-stream",
action="store_true",
help="Disable streaming output in the terminal",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
agent = AudioToolAgent(args.config)
stream_cb = None if args.no_stream else console_stream_callback
result = agent.process(
audio_path=args.audio,
question=args.question,
options=args.options,
stream_callback=stream_cb,
)
print("\n📋 Final Result:\n")
print(json.dumps(result, indent=2))
if args.output:
output_path = Path(args.output)
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(json.dumps(result, indent=2), encoding="utf-8")
print(f"\nResult saved to: {output_path}")
if __name__ == "__main__":
main()