KohyaSS/library/tensorboard_gui.py
JSTayco 7b5639cff5 Huge WIP
This is a massive WIP and should not be trusted or used right now. However, major milestones have been crossed. Both message boxes and file dialogs are now properly subprocessed and work on macOS. I think by extension, it may work on runpod environments as well, but that remains to be tested.
2023-03-30 01:40:00 -07:00

54 lines
1.4 KiB
Python

import os
import subprocess
import time
import gradio as gr
tensorboard_proc = None # I know... bad but heh
TENSORBOARD = 'tensorboard' if os.name == 'posix' else 'tensorboard.exe'
def start_tensorboard(logging_dir):
global tensorboard_proc
if not os.listdir(logging_dir):
print('Error: log folder is empty')
show_message_box(msg='Error: log folder is empty')
return
run_cmd = [f'{TENSORBOARD}', '--logdir', f'{logging_dir}']
print(run_cmd)
if tensorboard_proc is not None:
print(
'Tensorboard is already running. Terminating existing process before starting new one...'
)
stop_tensorboard()
# Start background process
print('Starting tensorboard...')
tensorboard_proc = subprocess.Popen(run_cmd)
# Wait for some time to allow TensorBoard to start up
time.sleep(5)
# Open the TensorBoard URL in the default browser
print('Opening tensorboard url in browser...')
import webbrowser
webbrowser.open('http://localhost:6006')
def stop_tensorboard():
print('Stopping tensorboard process...')
tensorboard_proc.kill()
print('...process stopped')
def gradio_tensorboard():
with gr.Row():
button_start_tensorboard = gr.Button('Start tensorboard')
button_stop_tensorboard = gr.Button('Stop tensorboard')
return (button_start_tensorboard, button_stop_tensorboard)