mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2024-08-29 01:18:33 +03:00
* added optional START_ID env flag to resume from that instance id * prepare_dataset: fix comparisons by using instance id's as int * aider bench complete_runtime: close runtime to close container * added matrix display of instance id for logging * fix typo in summarize_results.py saying summarise_results * changed start_id to skip_num to skip rows from dataset (start_id wasn't supportable) * doc changes about huggingface spaces to temporarily point back to OD
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import socket
|
|
|
|
|
|
def find_available_tcp_port() -> int:
|
|
"""Find an available TCP port, return -1 if none available."""
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
try:
|
|
sock.bind(('localhost', 0))
|
|
port = sock.getsockname()[1]
|
|
return port
|
|
except Exception:
|
|
return -1
|
|
finally:
|
|
sock.close()
|
|
|
|
|
|
def display_number_matrix(number: int) -> str | None:
|
|
if not 0 <= number <= 999:
|
|
return None
|
|
|
|
# Define the matrix representation for each digit
|
|
digits = {
|
|
'0': ['###', '# #', '# #', '# #', '###'],
|
|
'1': [' #', ' #', ' #', ' #', ' #'],
|
|
'2': ['###', ' #', '###', '# ', '###'],
|
|
'3': ['###', ' #', '###', ' #', '###'],
|
|
'4': ['# #', '# #', '###', ' #', ' #'],
|
|
'5': ['###', '# ', '###', ' #', '###'],
|
|
'6': ['###', '# ', '###', '# #', '###'],
|
|
'7': ['###', ' #', ' #', ' #', ' #'],
|
|
'8': ['###', '# #', '###', '# #', '###'],
|
|
'9': ['###', '# #', '###', ' #', '###'],
|
|
}
|
|
|
|
# alternatively, with leading zeros: num_str = f"{number:03d}"
|
|
num_str = str(number) # Convert to string without padding
|
|
|
|
result = []
|
|
for row in range(5):
|
|
line = ' '.join(digits[digit][row] for digit in num_str)
|
|
result.append(line)
|
|
|
|
matrix_display = '\n'.join(result)
|
|
return f'\n{matrix_display}\n'
|