tomiconic commited on
Commit
6ec55a5
·
verified ·
1 Parent(s): 8600168

Delete parser.py

Browse files
Files changed (1) hide show
  1. parser.py +0 -148
parser.py DELETED
@@ -1,148 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import re
4
- from dataclasses import dataclass, asdict
5
-
6
-
7
- @dataclass
8
- class PromptSpec:
9
- object_type: str = "cargo_hauler"
10
- scale: str = "small"
11
- hull_style: str = "boxy"
12
- engine_count: int = 2
13
- wing_span: float = 0.2
14
- cargo_ratio: float = 0.38
15
- cockpit_ratio: float = 0.18
16
- fin_height: float = 0.0
17
- landing_gear: bool = True
18
- asymmetry: float = 0.0
19
- notes: str = ""
20
-
21
- def to_dict(self) -> dict:
22
- return asdict(self)
23
-
24
-
25
- TYPE_KEYWORDS = {
26
- "fighter": "fighter",
27
- "combat": "fighter",
28
- "interceptor": "fighter",
29
- "shuttle": "shuttle",
30
- "freighter": "freighter",
31
- "hauler": "cargo_hauler",
32
- "cargo": "cargo_hauler",
33
- "transport": "cargo_hauler",
34
- "dropship": "dropship",
35
- "drone": "drone",
36
- }
37
-
38
- STYLE_KEYWORDS = {
39
- "boxy": "boxy",
40
- "industrial": "boxy",
41
- "hard-surface": "boxy",
42
- "rounded": "rounded",
43
- "sleek": "sleek",
44
- "streamlined": "sleek",
45
- "brutalist": "boxy",
46
- }
47
-
48
- SCALE_KEYWORDS = {
49
- "tiny": "small",
50
- "small": "small",
51
- "compact": "small",
52
- "medium": "medium",
53
- "mid-size": "medium",
54
- "large": "large",
55
- "heavy": "large",
56
- "huge": "large",
57
- }
58
-
59
- VALID_OBJECT_TYPES = {"cargo_hauler", "fighter", "shuttle", "freighter", "dropship", "drone"}
60
- VALID_SCALES = {"small", "medium", "large"}
61
- VALID_HULL_STYLES = {"boxy", "rounded", "sleek"}
62
-
63
-
64
- def _clamp(value: float, low: float, high: float) -> float:
65
- return max(low, min(high, value))
66
-
67
-
68
- def merge_prompt_specs(primary: PromptSpec, secondary: PromptSpec) -> PromptSpec:
69
- merged = PromptSpec(**primary.to_dict())
70
-
71
- if secondary.object_type in VALID_OBJECT_TYPES:
72
- merged.object_type = secondary.object_type
73
- if secondary.scale in VALID_SCALES:
74
- merged.scale = secondary.scale
75
- if secondary.hull_style in VALID_HULL_STYLES:
76
- merged.hull_style = secondary.hull_style
77
-
78
- merged.engine_count = int(_clamp(secondary.engine_count, 1, 6))
79
- merged.wing_span = float(_clamp(secondary.wing_span, 0.0, 0.6))
80
- merged.cargo_ratio = float(_clamp(secondary.cargo_ratio, 0.0, 0.65))
81
- merged.cockpit_ratio = float(_clamp(secondary.cockpit_ratio, 0.10, 0.30))
82
- merged.fin_height = float(_clamp(secondary.fin_height, 0.0, 0.3))
83
- merged.landing_gear = bool(secondary.landing_gear)
84
- merged.asymmetry = float(_clamp(secondary.asymmetry, 0.0, 0.2))
85
- merged.notes = secondary.notes or primary.notes
86
-
87
- if merged.object_type in {"fighter", "drone"}:
88
- merged.cargo_ratio = min(merged.cargo_ratio, 0.20)
89
- if merged.hull_style == "boxy":
90
- merged.hull_style = "sleek"
91
-
92
- return merged
93
-
94
-
95
- def parse_prompt(prompt: str) -> PromptSpec:
96
- text = prompt.lower().strip()
97
- spec = PromptSpec(notes=prompt.strip())
98
-
99
- for key, value in TYPE_KEYWORDS.items():
100
- if key in text:
101
- spec.object_type = value
102
- break
103
-
104
- for key, value in STYLE_KEYWORDS.items():
105
- if key in text:
106
- spec.hull_style = value
107
- break
108
-
109
- for key, value in SCALE_KEYWORDS.items():
110
- if key in text:
111
- spec.scale = value
112
- break
113
-
114
- if any(word in text for word in ["wing", "wings"]):
115
- spec.wing_span = 0.42 if spec.object_type == "fighter" else 0.28
116
- if any(word in text for word in ["no wings", "wingless"]):
117
- spec.wing_span = 0.0
118
-
119
- if any(word in text for word in ["cargo bay", "cargo hold", "container", "freight"]):
120
- spec.cargo_ratio = 0.48
121
-
122
- if any(word in text for word in ["big cockpit", "large cockpit", "glass nose"]):
123
- spec.cockpit_ratio = 0.24
124
- if any(word in text for word in ["small cockpit", "tiny cockpit"]):
125
- spec.cockpit_ratio = 0.13
126
-
127
- if any(word in text for word in ["fin", "tail", "vertical stabilizer"]):
128
- spec.fin_height = 0.18 if spec.object_type != "fighter" else 0.12
129
-
130
- if any(word in text for word in ["hover", "hovercraft", "antigrav"]):
131
- spec.landing_gear = False
132
-
133
- if spec.object_type in {"fighter", "drone"}:
134
- spec.engine_count = 1 if "single engine" in text else 2
135
- spec.cargo_ratio = min(spec.cargo_ratio, 0.18)
136
- spec.hull_style = "sleek"
137
- elif spec.object_type in {"cargo_hauler", "freighter", "dropship"}:
138
- spec.engine_count = 4 if any(x in text for x in ["4 engine", "four engine", "quad engine"]) else 2
139
- spec.hull_style = "boxy" if spec.hull_style == "sleek" else spec.hull_style
140
-
141
- numeric_engine = re.search(r"(\d+)\s*(?:engine|engines)", text)
142
- if numeric_engine:
143
- spec.engine_count = max(1, min(6, int(numeric_engine.group(1))))
144
-
145
- if any(word in text for word in ["asymmetric", "uneven", "offset"]):
146
- spec.asymmetry = 0.12
147
-
148
- return spec