-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
executable file
·99 lines (84 loc) · 2.67 KB
/
config.py
File metadata and controls
executable file
·99 lines (84 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import json
import os
import secrets
import logging
CONFIG_PATH = '/data/config.json'
# Default Configuration
DEFAULT_CONFIG = {
# System
"device": "cuda",
"webui_password": "",
"flask_secret_key": "",
"archive_zip": False,
"db_space_saver": True,
# Database
"db_type": "sqlite",
"db_address": "",
"db_name": "scribble",
"db_username": "",
"db_password": "",
# Whisper
"whisper_model": "small",
"whisper_threads": 0,
"whisper_batch_size": 16,
"whisper_beam_size": 5,
"whisper_compute_type": "int8",
"whisper_language": "en",
"whisper_no_speech_threshold": 0.45,
"whisper_compression_ratio_threshold": 1.8,
"whisper_condition_on_previous_text": True,
"whisper_initial_prompt": "",
"hf_token": "",
# VAD
"vad_method": "silero",
"vad_onset": 0.5,
"vad_offset": 0.363,
"vad_min_silence_ms": 1000,
"vad_max_speech_s": 20.0,
# LLM
"llm_provider": "Google",
"llm_model": "gemini-flash-latest",
"llm_api_key": "",
"llm_input_cost": 0.0,
"llm_output_cost": 0.0,
"ollama_url": ""
}
def load_config():
"""Load config from disk, or create with defaults if missing."""
if not os.path.exists('/data'):
os.makedirs('/data', exist_ok=True)
config = DEFAULT_CONFIG.copy()
if os.path.exists(CONFIG_PATH):
try:
with open(CONFIG_PATH, 'r') as f:
saved_config = json.load(f)
config.update(saved_config)
# Cleanup deprecated keys
keys_to_remove = [k for k in config if k not in DEFAULT_CONFIG]
if keys_to_remove:
for k in keys_to_remove:
del config[k]
save_config(config)
except Exception as e:
logging.error(f"Error loading config.json: {e}")
# Security: Generate WebUI Password if missing
if not config['webui_password']:
temp_pass = secrets.token_urlsafe(12)
config['webui_password'] = temp_pass
logging.warning("="*50)
logging.warning(f"FIRST RUN - TEMPORARY PASSWORD: {temp_pass}")
logging.warning("="*50)
save_config(config)
# Security: Generate Flask Secret Key if missing (NEW)
if not config['flask_secret_key']:
new_secret = secrets.token_hex(32)
config['flask_secret_key'] = new_secret
save_config(config)
return config
def save_config(config):
"""Save the current config to disk."""
try:
with open(CONFIG_PATH, 'w') as f:
json.dump(config, f, indent=4)
except Exception as e:
logging.error(f"Error saving config.json: {e}")