Update generate-cot.py
Browse filesfix counting between hours
- generate-cot.py +50 -111
generate-cot.py
CHANGED
|
@@ -23,11 +23,13 @@ def get_closest_numbers(time_str):
|
|
| 23 |
'min': get_position_info(minute_degrees)
|
| 24 |
}
|
| 25 |
|
| 26 |
-
def generate_time_description(clock_data):
|
| 27 |
|
| 28 |
clock_params = clock_data['clock_params']
|
| 29 |
clock_coordinates = clock_data['clock_coordinates']
|
| 30 |
time_str = clock_params['time']
|
|
|
|
|
|
|
| 31 |
is_unreadable = clock_params.get('isUnreadable', False)
|
| 32 |
hours_format = clock_params.get('hours_format', 'unknown')
|
| 33 |
hours_to_generate = clock_params.get('hours_to_generate', [])
|
|
@@ -43,9 +45,10 @@ def generate_time_description(clock_data):
|
|
| 43 |
decal_center = clock_coordinates.get('decal_center', [0, 0])
|
| 44 |
bg_width = clock_params.get('bgWidth', 1)
|
| 45 |
bg_height = clock_params.get('bgHeight', 1)
|
|
|
|
| 46 |
|
| 47 |
if is_unreadable:
|
| 48 |
-
if hours_format == 'line'
|
| 49 |
return random.choice([
|
| 50 |
"The clock is unreadable because the hour markers are lines and the clock is tilted, making it impossible to determine the 12 o'clock position without any landmarks on the clock.",
|
| 51 |
"Due to the tilted clock and line-shaped hour markers, it's impossible to identify the 12 o'clock position without any reference points, rendering the clock unreadable.",
|
|
@@ -53,7 +56,7 @@ def generate_time_description(clock_data):
|
|
| 53 |
"Without any landmarks and with line-shaped hour markers on a tilted clock, it's not possible to determine the 12 o'clock position, making the clock unreadable.",
|
| 54 |
"The combination of a tilted clock face and line-shaped hour markers makes it impossible to identify the 12 o'clock position, rendering the clock unreadable without additional reference points."
|
| 55 |
])
|
| 56 |
-
elif hours_format == 'none'
|
| 57 |
return random.choice([
|
| 58 |
"The clock is unreadable because there are no hour markers or decals to indicate the 12 o'clock position.",
|
| 59 |
"Without any hour markers or decals, it's impossible to determine the 12 o'clock position, making the clock unreadable.",
|
|
@@ -61,7 +64,7 @@ def generate_time_description(clock_data):
|
|
| 61 |
"Due to the lack of hour markers or decals, the clock is unreadable since the 12 o'clock position cannot be determined.",
|
| 62 |
"The clock's readability is compromised by the absence of hour markers or decals, making it impossible to locate the 12 o'clock position."
|
| 63 |
])
|
| 64 |
-
else:
|
| 65 |
return random.choice([
|
| 66 |
"The clock is unreadable due to insufficient markers or orientation cues.",
|
| 67 |
"Lack of adequate markers or orientation references makes the clock unreadable.",
|
|
@@ -117,18 +120,35 @@ def generate_time_description(clock_data):
|
|
| 117 |
real_closest_min = real_closest_res['min']
|
| 118 |
|
| 119 |
# Hour hand closest
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
if before_distance < after_distance:
|
| 124 |
-
hour_hand_relation = f"After the {format_point(hour_marker_points[before_hour_marker], before_hour_marker)} o'clock marker"
|
| 125 |
-
relevant_marker = before_hour_marker
|
| 126 |
else:
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
if not before_hour_marker == real_closest_hour['closest']:
|
| 131 |
-
hour_hand_relation = f"Between the {format_point(hour_marker_points[before_hour_marker], before_hour_marker)} and {format_point(hour_marker_points[after_hour_marker], after_hour_marker)} o'clock markers, {real_closest_hour['position']} where {real_closest_hour['closest']} would be"
|
| 132 |
|
| 133 |
|
| 134 |
|
|
@@ -157,23 +177,17 @@ def generate_time_description(clock_data):
|
|
| 157 |
# minute_hand_relation = f"between the {format_point(tick_positions[str(before_minute_tick)], before_minute_tick // 6)} and {format_point(tick_positions[str(after_minute_tick)], after_minute_tick // 6)} minute marks"
|
| 158 |
|
| 159 |
|
| 160 |
-
minute_distances = {int(marker): distance(pos, minute_hand_tip) for marker, pos in hour_marker_points.items()}
|
| 161 |
-
closest_minute_marker = min(minute_distances, key=minute_distances.get)
|
| 162 |
-
before_minute_marker, after_minute_marker = get_adjacent_markers(list(hour_marker_points.keys()), str(closest_minute_marker))
|
| 163 |
|
| 164 |
-
before_distance = distance(hour_marker_points[before_minute_marker], minute_hand_tip)
|
| 165 |
-
after_distance = distance(hour_marker_points[after_minute_marker], minute_hand_tip)
|
| 166 |
|
| 167 |
-
if before_distance < after_distance:
|
| 168 |
-
minute_hand_relation = f"just after the {format_point(hour_marker_points[before_minute_marker], before_minute_marker)} o'clock marker"
|
| 169 |
-
relevant_minute_marker = before_minute_marker
|
| 170 |
-
else:
|
| 171 |
-
minute_hand_relation = f"just before the {format_point(hour_marker_points[after_minute_marker], after_minute_marker)} o'clock marker"
|
| 172 |
-
relevant_minute_marker = after_minute_marker
|
| 173 |
|
| 174 |
-
|
| 175 |
-
if
|
| 176 |
-
minute_hand_relation = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# Generate phrases based on the clock parameters
|
| 179 |
hour_format_phrases = {
|
|
@@ -196,7 +210,6 @@ def generate_time_description(clock_data):
|
|
| 196 |
# give a point the model can orient around, will always have 12, 6, or 3, but prefer 12 then 6
|
| 197 |
decal_phrase = ""
|
| 198 |
if hours_format in ['line', 'none'] and should_have_decal:
|
| 199 |
-
print('aaaaa')
|
| 200 |
if '12' in hour_marker_points:
|
| 201 |
decal_phrase = (
|
| 202 |
f"Using the decal on the clock's {decal_position}, we know where {format_point(hour_marker_points['12'], '12')} is on this clock and can orient around it."
|
|
@@ -214,13 +227,13 @@ def generate_time_description(clock_data):
|
|
| 214 |
|
| 215 |
hour_hand_phrases = [
|
| 216 |
f"The {format_point(hour_hand_tip, 'hour hand')} is {hour_hand_relation}.",
|
| 217 |
-
f"
|
| 218 |
-
f"The
|
| 219 |
]
|
| 220 |
minute_hand_phrases = [
|
| 221 |
f"The {format_point(minute_hand_tip, 'minute hand')} is {minute_hand_relation}.",
|
| 222 |
-
f"
|
| 223 |
-
f"The
|
| 224 |
]
|
| 225 |
angle_phrase = f"The angle between the hour and minute hands is approximately {angle:.2f} degrees."
|
| 226 |
conclusion_phrases = [
|
|
@@ -229,12 +242,12 @@ def generate_time_description(clock_data):
|
|
| 229 |
f"As a result, the time is {hour:02d}:{minute:02d}."
|
| 230 |
]
|
| 231 |
|
| 232 |
-
#
|
| 233 |
description = " ".join(filter(None, [
|
| 234 |
hour_marker_phrase,
|
| 235 |
hour_marker_count_phrase,
|
| 236 |
-
smaller_tick_phrase,
|
| 237 |
-
second_hand_phrase,
|
| 238 |
decal_phrase,
|
| 239 |
random.choice(hour_hand_phrases),
|
| 240 |
random.choice(minute_hand_phrases),
|
|
@@ -245,79 +258,5 @@ def generate_time_description(clock_data):
|
|
| 245 |
return description
|
| 246 |
|
| 247 |
|
| 248 |
-
clock_data = {
|
| 249 |
-
"clock_params": {
|
| 250 |
-
"fontSize": 82,
|
| 251 |
-
"hour_marker_radius": 100,
|
| 252 |
-
"hours_to_generate": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
| 253 |
-
"should_tilt_hours": True,
|
| 254 |
-
"font": "Times New Roman",
|
| 255 |
-
"hours_format": "line",
|
| 256 |
-
"outer_border_color": [0, 0, 0],
|
| 257 |
-
"outer_border_width": 9,
|
| 258 |
-
"smaller_tick_frequency": 6,
|
| 259 |
-
"has_smaller_ticks": True,
|
| 260 |
-
"has_larger_ticks": False,
|
| 261 |
-
"time": "01:38:25",
|
| 262 |
-
"using_image_hands": True,
|
| 263 |
-
"has_second_hand": False,
|
| 264 |
-
"hour_hand_front_len": 55,
|
| 265 |
-
"hour_hand_back_len": 5.5,
|
| 266 |
-
"hour_hand_width": 45,
|
| 267 |
-
"minute_hand_front_len": 86,
|
| 268 |
-
"minute_hand_back_len": 7.166666666666667,
|
| 269 |
-
"minute_hand_width": 30,
|
| 270 |
-
"second_hand_front_len": 66,
|
| 271 |
-
"second_hand_back_len": 6.6,
|
| 272 |
-
"second_hand_width": 4,
|
| 273 |
-
"decal_image_index": 0,
|
| 274 |
-
"hr_image_index": 4,
|
| 275 |
-
"min_image_index": 4,
|
| 276 |
-
"decal_scale": 0.3077502934453228,
|
| 277 |
-
"should_have_decal": True,
|
| 278 |
-
"decal_position": "right",
|
| 279 |
-
"ticks_inside": True,
|
| 280 |
-
"ticks_are_dots": False,
|
| 281 |
-
"use_rounded_line_endings": True,
|
| 282 |
-
"rotationX": -54.67108931132457,
|
| 283 |
-
"rotationY": 32.946092388345136,
|
| 284 |
-
"rotationZ": 0,
|
| 285 |
-
"translationX": 0.7226896871641983,
|
| 286 |
-
"translationY": 0.32557091472462885,
|
| 287 |
-
"clockScale": 0.2944735397200734,
|
| 288 |
-
"is_square_clock": False,
|
| 289 |
-
"isUnreadable": False,
|
| 290 |
-
"background_image": "background-0.jpg",
|
| 291 |
-
"background_rotation": 0,
|
| 292 |
-
"invert_background": False,
|
| 293 |
-
"reverse_background": True,
|
| 294 |
-
"bgWidth": 1024,
|
| 295 |
-
"bgHeight": 696
|
| 296 |
-
},
|
| 297 |
-
"clock_coordinates": {
|
| 298 |
-
"hour_marker_points": {
|
| 299 |
-
# "1": [840.7229584915374, 388.8294035200205],
|
| 300 |
-
# "2": [864.708426987622, 405.3574644148344],
|
| 301 |
-
"3": [873.4877177788603, 427.9352154724463],
|
| 302 |
-
# "4": [864.708426987622, 450.51296653005824],
|
| 303 |
-
# "5": [840.7229584915374, 467.04102742487214],
|
| 304 |
-
"6": [807.9581992042145, 473.09071758767016],
|
| 305 |
-
# "7": [775.1934399168915, 467.04102742487214],
|
| 306 |
-
# "8": [751.2079714208069, 450.51296653005824],
|
| 307 |
-
"9": [742.4286806295686, 427.9352154724463],
|
| 308 |
-
# "10": [751.2079714208069, 405.3574644148344],
|
| 309 |
-
# "11": [775.1934399168915, 388.8294035200205],
|
| 310 |
-
"12": [807.9581992042145, 382.7797133572225]
|
| 311 |
-
},
|
| 312 |
-
"hand_tips": {
|
| 313 |
-
"hour": [846.4389307129645, 404.88473026091174],
|
| 314 |
-
"minute": [747.3718624157557, 462.3506187558278]
|
| 315 |
-
},
|
| 316 |
-
"tick_positions": {
|
| 317 |
-
# Tick positions data (omitted for brevity)
|
| 318 |
-
},
|
| 319 |
-
"decal_center": [849.3226328451655, 427.9352154724463]
|
| 320 |
-
}
|
| 321 |
-
}
|
| 322 |
|
| 323 |
-
|
|
|
|
| 23 |
'min': get_position_info(minute_degrees)
|
| 24 |
}
|
| 25 |
|
| 26 |
+
def generate_time_description(clock_data, should_use_12=True):
|
| 27 |
|
| 28 |
clock_params = clock_data['clock_params']
|
| 29 |
clock_coordinates = clock_data['clock_coordinates']
|
| 30 |
time_str = clock_params['time']
|
| 31 |
+
if should_use_12 and time_str.startswith('00'):
|
| 32 |
+
time_str = '12' + time_str[2:]
|
| 33 |
is_unreadable = clock_params.get('isUnreadable', False)
|
| 34 |
hours_format = clock_params.get('hours_format', 'unknown')
|
| 35 |
hours_to_generate = clock_params.get('hours_to_generate', [])
|
|
|
|
| 45 |
decal_center = clock_coordinates.get('decal_center', [0, 0])
|
| 46 |
bg_width = clock_params.get('bgWidth', 1)
|
| 47 |
bg_height = clock_params.get('bgHeight', 1)
|
| 48 |
+
hours_generated = clock_params.get('hours_to_generate')
|
| 49 |
|
| 50 |
if is_unreadable:
|
| 51 |
+
if hours_format == 'line':
|
| 52 |
return random.choice([
|
| 53 |
"The clock is unreadable because the hour markers are lines and the clock is tilted, making it impossible to determine the 12 o'clock position without any landmarks on the clock.",
|
| 54 |
"Due to the tilted clock and line-shaped hour markers, it's impossible to identify the 12 o'clock position without any reference points, rendering the clock unreadable.",
|
|
|
|
| 56 |
"Without any landmarks and with line-shaped hour markers on a tilted clock, it's not possible to determine the 12 o'clock position, making the clock unreadable.",
|
| 57 |
"The combination of a tilted clock face and line-shaped hour markers makes it impossible to identify the 12 o'clock position, rendering the clock unreadable without additional reference points."
|
| 58 |
])
|
| 59 |
+
elif hours_format == 'none':
|
| 60 |
return random.choice([
|
| 61 |
"The clock is unreadable because there are no hour markers or decals to indicate the 12 o'clock position.",
|
| 62 |
"Without any hour markers or decals, it's impossible to determine the 12 o'clock position, making the clock unreadable.",
|
|
|
|
| 64 |
"Due to the lack of hour markers or decals, the clock is unreadable since the 12 o'clock position cannot be determined.",
|
| 65 |
"The clock's readability is compromised by the absence of hour markers or decals, making it impossible to locate the 12 o'clock position."
|
| 66 |
])
|
| 67 |
+
else: #shouldn't get here, but in case we add more
|
| 68 |
return random.choice([
|
| 69 |
"The clock is unreadable due to insufficient markers or orientation cues.",
|
| 70 |
"Lack of adequate markers or orientation references makes the clock unreadable.",
|
|
|
|
| 120 |
real_closest_min = real_closest_res['min']
|
| 121 |
|
| 122 |
# Hour hand closest
|
| 123 |
+
def find_closest_neighbors(arr, target):
|
| 124 |
+
|
| 125 |
+
# Sort the array to make finding neighbors easier
|
| 126 |
+
sorted_arr = sorted(arr)
|
| 127 |
+
|
| 128 |
+
# If target is smaller than all elements
|
| 129 |
+
if target < sorted_arr[0]:
|
| 130 |
+
return str(sorted_arr[-1]), str(sorted_arr[0])
|
| 131 |
+
|
| 132 |
+
# If target is larger than all elements
|
| 133 |
+
if target > sorted_arr[-1]:
|
| 134 |
+
return str(sorted_arr[-1]), str(sorted_arr[0])
|
| 135 |
+
|
| 136 |
+
# Find the right neighbor (first element larger than target)
|
| 137 |
+
right_idx = 0
|
| 138 |
+
while right_idx < len(sorted_arr) and sorted_arr[right_idx] < target:
|
| 139 |
+
right_idx += 1
|
| 140 |
+
|
| 141 |
+
# The left neighbor is the element before the right neighbor
|
| 142 |
+
left_idx = right_idx - 1
|
| 143 |
+
|
| 144 |
+
return str(sorted_arr[left_idx]), str(sorted_arr[right_idx])
|
| 145 |
+
|
| 146 |
+
if real_closest_hour['closest'] in hours_generated:
|
| 147 |
+
hour_hand_relation = f"{real_closest_hour['position']} the {format_point(hour_marker_points[str(real_closest_hour['closest'])], str(real_closest_hour['closest']))} o'clock marker"
|
| 148 |
|
|
|
|
|
|
|
|
|
|
| 149 |
else:
|
| 150 |
+
smaller, larger = find_closest_neighbors(hours_generated, real_closest_hour['closest'])
|
| 151 |
+
hour_hand_relation = f"between the {format_point(hour_marker_points[smaller], smaller)} and {format_point(hour_marker_points[larger], larger)} o'clock markers, {real_closest_hour['position']} where the {real_closest_hour['closest']} would be"
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
|
| 154 |
|
|
|
|
| 177 |
# minute_hand_relation = f"between the {format_point(tick_positions[str(before_minute_tick)], before_minute_tick // 6)} and {format_point(tick_positions[str(after_minute_tick)], after_minute_tick // 6)} minute marks"
|
| 178 |
|
| 179 |
|
| 180 |
+
# minute_distances = {int(marker): distance(pos, minute_hand_tip) for marker, pos in hour_marker_points.items()}
|
|
|
|
|
|
|
| 181 |
|
|
|
|
|
|
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
|
| 185 |
+
if real_closest_min['closest'] in hours_generated:
|
| 186 |
+
minute_hand_relation = f"{real_closest_min['position']} the {format_point(hour_marker_points[str(real_closest_min['closest'])], str(real_closest_min['closest']))} o'clock marker"
|
| 187 |
+
|
| 188 |
+
else:
|
| 189 |
+
smaller, larger = find_closest_neighbors(hours_generated, real_closest_min['closest'])
|
| 190 |
+
minute_hand_relation = f"between the {format_point(hour_marker_points[smaller], smaller)} and {format_point(hour_marker_points[larger], larger)} o'clock markers, {real_closest_min['position']} where the {real_closest_min['closest']} would be"
|
| 191 |
|
| 192 |
# Generate phrases based on the clock parameters
|
| 193 |
hour_format_phrases = {
|
|
|
|
| 210 |
# give a point the model can orient around, will always have 12, 6, or 3, but prefer 12 then 6
|
| 211 |
decal_phrase = ""
|
| 212 |
if hours_format in ['line', 'none'] and should_have_decal:
|
|
|
|
| 213 |
if '12' in hour_marker_points:
|
| 214 |
decal_phrase = (
|
| 215 |
f"Using the decal on the clock's {decal_position}, we know where {format_point(hour_marker_points['12'], '12')} is on this clock and can orient around it."
|
|
|
|
| 227 |
|
| 228 |
hour_hand_phrases = [
|
| 229 |
f"The {format_point(hour_hand_tip, 'hour hand')} is {hour_hand_relation}.",
|
| 230 |
+
f"The clock's {format_point(hour_hand_tip, 'hour hand tip')} lies {hour_hand_relation}.",
|
| 231 |
+
f"The {format_point(hour_hand_tip, 'hour hand tip')} points {hour_hand_relation}."
|
| 232 |
]
|
| 233 |
minute_hand_phrases = [
|
| 234 |
f"The {format_point(minute_hand_tip, 'minute hand')} is {minute_hand_relation}.",
|
| 235 |
+
f"The {format_point(minute_hand_tip, 'minute hand')} lies {minute_hand_relation}.",
|
| 236 |
+
f"The {format_point(minute_hand_tip, 'minute hand tip')} points {minute_hand_relation}."
|
| 237 |
]
|
| 238 |
angle_phrase = f"The angle between the hour and minute hands is approximately {angle:.2f} degrees."
|
| 239 |
conclusion_phrases = [
|
|
|
|
| 242 |
f"As a result, the time is {hour:02d}:{minute:02d}."
|
| 243 |
]
|
| 244 |
|
| 245 |
+
# ignore smaller ticks and second hand imo
|
| 246 |
description = " ".join(filter(None, [
|
| 247 |
hour_marker_phrase,
|
| 248 |
hour_marker_count_phrase,
|
| 249 |
+
# smaller_tick_phrase,
|
| 250 |
+
# second_hand_phrase,
|
| 251 |
decal_phrase,
|
| 252 |
random.choice(hour_hand_phrases),
|
| 253 |
random.choice(minute_hand_phrases),
|
|
|
|
| 258 |
return description
|
| 259 |
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
|
| 262 |
+
|