-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (63 loc) · 2.42 KB
/
Copy pathmain.py
File metadata and controls
79 lines (63 loc) · 2.42 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import argparse
import logging
import sys
from pathlib import Path
from src.parser.converter import DatasheetConverter
from src.parser.mapper import RFMapper
from src.generator.codegen import DriverGenerator
def setup_logging():
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler(sys.stdout)
]
)
def main():
setup_logging()
logger = logging.getLogger(__name__)
parser = argparse.ArgumentParser(description="Automated RF Driver Data Extraction Engine")
parser.add_argument("--input", "-i", type=str, required=True, help="Path to input PDF datasheet")
parser.add_argument("--output", "-o", type=str, default="output_driver.c", help="Path to output driver file")
args = parser.parse_args()
input_path = Path(args.input)
if not input_path.exists():
logger.error(f"Input file not found: {input_path}")
sys.exit(1)
# 1. Convert
logger.info("Initializing Converter (this may take time on first run)...")
try:
converter = DatasheetConverter() # Uses SmolDocling
except Exception as e:
logger.critical(f"Failed to initialize converter: {e}")
sys.exit(1)
logger.info(f"Processing {input_path}...")
try:
extraction_result = converter.convert(input_path)
except Exception as e:
logger.error(f"Conversion failed: {e}")
sys.exit(1)
# 2. Map
logger.info("Mapping extracted data to RF schema...")
# Debug: Save markdown
debug_md_path = input_path.with_suffix('.md')
try:
with open(debug_md_path, "w") as f:
f.write(extraction_result.get("markdown", ""))
logger.info(f"Debug markdown saved to {debug_md_path}")
except Exception as e:
logger.warning(f"Could not save debug markdown: {e}")
mapper = RFMapper()
mapped_data = mapper.map_data(extraction_result)
# Artifact: Summary Log
# In a real agentic flow, we might save this map to a file for review.
# For now, we just log it.
# 3. Generate
logger.info("Generating driver code...")
template_dir = Path("templates")
generator = DriverGenerator(template_dir)
output_path = Path(args.output)
generator.generate(mapped_data, output_path)
logger.info(f"Success! Driver code generated at {output_path}")
if __name__ == "__main__":
main()