Skip to content

Commit e226abd

Browse files
committed
Ruff formatting and fixes
1 parent 4ccf5aa commit e226abd

86 files changed

Lines changed: 3330 additions & 1928 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app.py

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,18 @@
5050
except FileNotFoundError:
5151
config = {}
5252

53-
_GENERAL = config.get('general') or {}
53+
_GENERAL = config.get("general") or {}
5454

5555
_LOG_LEVELS = {
5656
"debug": logging.DEBUG,
5757
"info": logging.INFO,
5858
"warning": logging.WARNING,
5959
"error": logging.ERROR,
6060
}
61-
_log_level_name = str(_GENERAL.get('log_level', 'info')).lower()
61+
_log_level_name = str(_GENERAL.get("log_level", "info")).lower()
6262
LOG_LEVEL = _LOG_LEVELS.get(_log_level_name, logging.INFO)
6363

64-
logging.basicConfig(
65-
level=LOG_LEVEL,
66-
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
67-
)
64+
logging.basicConfig(level=LOG_LEVEL, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
6865
logger = logging.getLogger(__name__)
6966
if _log_level_name not in _LOG_LEVELS:
7067
logger.warning(f"Unknown general.log_level {_log_level_name!r}; using info")
@@ -113,15 +110,14 @@
113110
logging.getLogger(_noisy).setLevel(_third_party_level)
114111
# "Setting pad_token_id to eos_token_id" fires at WARNING on every
115112
# transformers.generate call — silence just that submodule.
116-
logging.getLogger("transformers.generation.utils").setLevel(
117-
max(LOG_LEVEL, logging.ERROR)
118-
)
113+
logging.getLogger("transformers.generation.utils").setLevel(max(LOG_LEVEL, logging.ERROR))
119114

120115
# Drop llama-cpp-python's INFO chatter (model loader, CUDA init, KV-cache
121116
# layout, and per-call perf timings — the dashboard stats panel reports those
122117
# now). Warnings and errors always pass through. Installed before any
123118
# `Llama(...)` instantiation. Skipped on the CPU image (no llama_cpp).
124119
if llama_cpp is not None:
120+
125121
@llama_cpp.llama_log_callback
126122
def _filtered_llama_log(level, text, user_data):
127123
# ggml log levels: 1=INFO, 2=WARN, 3=ERROR, 4=DEBUG, 5=CONT.
@@ -160,11 +156,22 @@ def _filtered_llama_log(level, text, user_data):
160156
# The values are read fresh in `_assistant_args()` at Phase B (so a config the
161157
# wizard just wrote is picked up); this is just the key list.
162158
_ASSISTANT_OPTION_KEYS = (
163-
'wakeword_pattern', 'voice_clone', 'tts_speed', 'barge_in', 'barge_in_threshold_dbfs',
164-
'follow_up_time', 'input_device', 'output_device', 'asr_language',
165-
'asr_context_hint', 'asr_context_terms', 'use_vad', 'vad_threshold',
166-
'vad_endpoint_silence_ms', 'vad_min_speech_ms',
167-
'vad_soft_endpoint_silence_ms',
159+
"wakeword_pattern",
160+
"voice_clone",
161+
"tts_speed",
162+
"barge_in",
163+
"barge_in_threshold_dbfs",
164+
"follow_up_time",
165+
"input_device",
166+
"output_device",
167+
"asr_language",
168+
"asr_context_hint",
169+
"asr_context_terms",
170+
"use_vad",
171+
"vad_threshold",
172+
"vad_endpoint_silence_ms",
173+
"vad_min_speech_ms",
174+
"vad_soft_endpoint_silence_ms",
168175
)
169176

170177
from core.assistant import Assistant
@@ -188,20 +195,22 @@ def _read_config():
188195

189196
def _assistant_args(cfg):
190197
"""Extract the Assistant constructor args from a fresh config dict."""
191-
general = cfg.get('general') or {}
192-
options = {
193-
k: general[k] for k in _ASSISTANT_OPTION_KEYS if general.get(k) is not None
194-
}
195-
return general.get('wakeword'), cfg.get('models'), options
198+
general = cfg.get("general") or {}
199+
options = {k: general[k] for k in _ASSISTANT_OPTION_KEYS if general.get(k) is not None}
200+
return general.get("wakeword"), cfg.get("models"), options
196201

197202

198203
def _start_dashboard(context, host, port, certfile, keyfile):
199204
"""Start the single dashboard server (setup + run share it). Never fatal."""
200205
try:
201206
from server.dashboard import start_dashboard
207+
202208
start_dashboard(
203-
host=host, port=int(port),
204-
ssl_certfile=certfile, ssl_keyfile=keyfile, context=context,
209+
host=host,
210+
port=int(port),
211+
ssl_certfile=certfile,
212+
ssl_keyfile=keyfile,
213+
context=context,
205214
)
206215
scheme = "https" if (certfile and keyfile) else "http"
207216
logger.info("=" * 60)
@@ -221,11 +230,11 @@ def main():
221230
# Read config fresh (it may have just been seeded) and derive dashboard
222231
# settings + the setup decision from it.
223232
cfg = _read_config()
224-
general = cfg.get('general') or {}
225-
dash_port = general.get('dashboard_port')
226-
dash_host = general.get('dashboard_host', '127.0.0.1')
227-
dash_cert = general.get('dashboard_ssl_certfile')
228-
dash_key = general.get('dashboard_ssl_keyfile')
233+
general = cfg.get("general") or {}
234+
dash_port = general.get("dashboard_port")
235+
dash_host = general.get("dashboard_host", "127.0.0.1")
236+
dash_cert = general.get("dashboard_ssl_certfile")
237+
dash_key = general.get("dashboard_ssl_keyfile")
229238

230239
# Phase A: decide whether first-run setup is needed before loading anything.
231240
decision = detect_setup_state(cfg)
@@ -240,9 +249,7 @@ def main():
240249
if decision.needs_setup:
241250
phase = ERROR if decision.config_error else NEEDS_SETUP
242251
detail = decision.config_error or decision.reason
243-
lifecycle = Lifecycle(
244-
phase=phase, detail=detail, missing_assets=decision.missing_assets
245-
)
252+
lifecycle = Lifecycle(phase=phase, detail=detail, missing_assets=decision.missing_assets)
246253
else:
247254
lifecycle = Lifecycle(phase=LOADING)
248255

@@ -252,8 +259,7 @@ def main():
252259
# wizard's install endpoint downloads models then releases the block below,
253260
# and the assistant is attached to this same server (no second server).
254261
if decision.needs_setup:
255-
_start_dashboard(context, dash_host, dash_port or _SETUP_FALLBACK_PORT,
256-
dash_cert, dash_key)
262+
_start_dashboard(context, dash_host, dash_port or _SETUP_FALLBACK_PORT, dash_cert, dash_key)
257263
elif dash_port:
258264
_start_dashboard(context, dash_host, dash_port, dash_cert, dash_key)
259265

@@ -283,9 +289,7 @@ def main():
283289
if not wakeword:
284290
logger.error("No wakeword configured; cannot start. Re-run setup.")
285291
return
286-
assistant = Assistant(
287-
wakeword=wakeword, models=models, lifecycle=lifecycle, **options
288-
)
292+
assistant = Assistant(wakeword=wakeword, models=models, lifecycle=lifecycle, **options)
289293
context.set_assistant(assistant)
290294
assistant.run()
291295

audio/beep_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def set_output_device(self, device) -> None:
2222
self.device = device
2323

2424
def _play_beep(self, filename: str):
25-
data, samplerate = sf.read(_WAV_DIR / filename, dtype='float32')
25+
data, samplerate = sf.read(_WAV_DIR / filename, dtype="float32")
2626
sd.play(data, samplerate, device=self.device)
2727
sd.wait()
2828

0 commit comments

Comments
 (0)