62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
import os
|
|
import tomllib
|
|
|
|
CONFIG_PATH = os.path.expanduser("~/.config/tueit-transcriber/config.toml")
|
|
|
|
DEFAULTS = {
|
|
"ollama": {
|
|
"base_url": "http://localhost:11434",
|
|
"model": "gemma3:12b",
|
|
},
|
|
"whisper": {
|
|
"model": "large-v3",
|
|
"language": "de",
|
|
"device": "auto", # "auto" = use GPU if ROCm available, else CPU
|
|
},
|
|
"server": {
|
|
"port": 8765,
|
|
},
|
|
"output": {
|
|
"path": os.path.expanduser(
|
|
"~/cloud.shron.de/Hetzner Storagebox/work"
|
|
),
|
|
},
|
|
"network": {
|
|
"host": "127.0.0.1",
|
|
},
|
|
"pid_file": os.path.expanduser("~/.local/run/tueit-transcriber.pid"),
|
|
}
|
|
|
|
|
|
def load() -> dict:
|
|
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
|
|
if not os.path.exists(CONFIG_PATH):
|
|
_write_defaults()
|
|
with open(CONFIG_PATH, "rb") as f:
|
|
on_disk = tomllib.load(f)
|
|
return _deep_merge(DEFAULTS, on_disk)
|
|
|
|
|
|
def _deep_merge(base: dict, override: dict) -> dict:
|
|
result = dict(base)
|
|
for k, v in override.items():
|
|
if k in result and isinstance(result[k], dict) and isinstance(v, dict):
|
|
result[k] = _deep_merge(result[k], v)
|
|
else:
|
|
result[k] = v
|
|
return result
|
|
|
|
|
|
def _write_defaults():
|
|
try:
|
|
import tomli_w
|
|
with open(CONFIG_PATH, "wb") as f:
|
|
tomli_w.dump(DEFAULTS, f)
|
|
except ImportError:
|
|
with open(CONFIG_PATH, "w") as f:
|
|
f.write("# tüit Transkriptor config\n\n")
|
|
f.write('[ollama]\nbase_url = "http://localhost:11434"\nmodel = "gemma3:12b"\n\n')
|
|
f.write('[whisper]\nmodel = "large-v3"\nlanguage = "de"\ndevice = "auto"\n\n')
|
|
f.write('[server]\nport = 8765\n\n')
|
|
f.write(f'[output]\npath = "{DEFAULTS["output"]["path"]}"\n')
|