Skip to content

Commit

Permalink
fixed codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
matt200-ok committed Jan 16, 2025
1 parent c0b1655 commit b6ea59b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
47 changes: 26 additions & 21 deletions recipes/llm-voice-assistant/python/windows_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def close(self):
try:
self.orca_connection.send({'command': Commands.CLOSE})
self.orca_process.join(1.0)
except:
except Exception as e:
sys.stderr.write(str(e))
self.orca_process.kill()

def start(self):
Expand All @@ -171,8 +172,8 @@ def interrupt(self):
while self.orca_connection.poll() and self.orca_connection.recv()['command'] != Commands.INTERRUPT:
time.sleep(0.1)
self.speaker.interrupt()
except:
pass
except Exception as e:
sys.stderr.write(str(e))

def tick(self):
while self.orca_connection.poll():
Expand Down Expand Up @@ -261,7 +262,8 @@ def close(self):
try:
self.pllm_connection.send({'command': Commands.CLOSE})
self.pllm_process.join(1.0)
except:
except Exception as e:
sys.stderr.write(str(e))
self.pllm_process.kill()

def process(self, text: str):
Expand Down Expand Up @@ -457,7 +459,7 @@ def reset():

@staticmethod
def goto(y, x):
return f"\u001B[{y+1};{x+1}H"
return f"\u001B[{y + 1};{x + 1}H"

@staticmethod
def color(col):
Expand All @@ -467,7 +469,7 @@ def color(col):
def present():
sys.stdout.flush()

def __init__(self, height, width, y = 0, x = 0):
def __init__(self, height, width, y=0, x=0):
self.height = height
self.width = width
self.y = y
Expand All @@ -490,14 +492,14 @@ def write(self, y, x, *args):
sys.stdout.write(text)

def box(self):
TOP = '┌' + '─' * (self.width - 2) + '┐'
ROW = '│' + ' ' * (self.width - 2) + '│'
BOTTOM = '└' + '─' * (self.width - 2) + '┘'
top = '┌' + '─' * (self.width - 2) + '┐'
row = '│' + ' ' * (self.width - 2) + '│'
bottom = '└' + '─' * (self.width - 2) + '┘'
sys.stdout.write(Window.color([0]))
sys.stdout.write(Window.goto(self.y, self.x) + TOP)
sys.stdout.write(Window.goto(self.y, self.x) + top)
for i in range(1, self.height - 1):
sys.stdout.write(Window.goto(self.y + i, self.x) + ROW)
sys.stdout.write(Window.goto(self.y + self.height - 1, self.x) + BOTTOM)
sys.stdout.write(Window.goto(self.y + i, self.x) + row)
sys.stdout.write(Window.goto(self.y + self.height - 1, self.x) + bottom)


class VerticalBar:
Expand Down Expand Up @@ -632,12 +634,14 @@ def render_title(self):
display = line.center(self.title.width, '░')
self.title.write(i, 0, display)

def render_prompt(self, text_state = None):
def render_prompt(self, text_state=None):
if text_state:
self.text_state = text_state

self.prompt.clear()
self.prompt.write(0, 1, Window.color([90]) if self.in_blink else '', '> ', Window.color([0]), self.prompt_text[self.text_state])
self.prompt.write(0, 1,
Window.color([90]) if self.in_blink else '', '> ',
Window.color([0]), self.prompt_text[self.text_state])

def tick(self):
self.prev_time = self.current_time
Expand Down Expand Up @@ -732,8 +736,8 @@ def handler(_, __) -> None:
'text': f"{math.ceil(cpu_usage)}%",
'bar': (cpu_usage / 100)
})
except:
pass
except Exception as e:
sys.stderr.write(str(e))

@staticmethod
def worker_gpu(queue: Queue, should_close, pids: list):
Expand All @@ -742,7 +746,8 @@ def handler(_, __) -> None:
signal.signal(signal.SIGINT, handler)

try:
gpu_usage_counters = ', '.join([r'"\GPU Engine(pid_{}_*)\Utilization Percentage"'.format(pid) for pid in pids])
gpu_usage_counters_format = r'"\GPU Engine(pid_{}_*)\Utilization Percentage"'
gpu_usage_counters = ', '.join([gpu_usage_counters_format.format(pid) for pid in pids])
gpu_usage_cmd = r'(((Get-Counter {}).CounterSamples | where CookedValue).CookedValue | measure -sum).sum'
gpu_usage_cmd = gpu_usage_cmd.format(gpu_usage_counters)
while not should_close.is_set():
Expand All @@ -755,8 +760,8 @@ def handler(_, __) -> None:
'text': f"{math.ceil(gpu_usage)}%",
'bar': (float(gpu_usage) / 100)
})
except:
pass
except Exception as e:
sys.stderr.write(str(e))

@staticmethod
def worker_ram(queue: Queue, should_close, pids: list):
Expand All @@ -776,8 +781,8 @@ def handler(_, __) -> None:
'text': f"{round(ram_usage, 2)}GB / {round(ram_total, 2)}GB",
'bar': (float(ram_usage) / float(ram_total))
})
except:
pass
except Exception as e:
sys.stderr.write(str(e))


def main(config):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ pvorca==1.0.1
pvporcupine==3.0.4
pvrecorder==1.2.4
pvspeaker==1.0.4
windows-curses==2.4.0; sys_platform == 'win32'
psutil==6.1.1; sys_platform == 'win32'
psutil==6.1.1

0 comments on commit b6ea59b

Please sign in to comment.