refactor(voice_to_text_tray): improve configuration handling
- Replace direct usage of global configuration dictionaries with local variables for better readability and maintainability. - Update all references to use the newly introduced local variables. Signed-off-by: Max P. <Mail@MPassarello.de>
This commit is contained in:
@@ -32,15 +32,18 @@ class WhisperWorker(QThread):
|
|||||||
finished = pyqtSignal(str)
|
finished = pyqtSignal(str)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
CURENT_CONFIGURATION_LOCALE = CONFIGURATION
|
||||||
|
CURRENT_PRESET_LOCALE = CURRENT_PRESET
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Whisper ausführen
|
# Whisper ausführen
|
||||||
whisper_cmd = [
|
whisper_cmd = [
|
||||||
CONFIGURATION["whisper_path"],
|
CURENT_CONFIGURATION_LOCALE["whisper_path"],
|
||||||
"-m", CURRENT_PRESET["whisper_model"],
|
"-m", CURRENT_PRESET_LOCALE["whisper_model"],
|
||||||
"-f", CONFIGURATION["audio_file"],
|
"-f", CURENT_CONFIGURATION_LOCALE["audio_file"],
|
||||||
"-l", CURRENT_PRESET["language"],
|
"-l", CURRENT_PRESET_LOCALE["language"],
|
||||||
"-otxt",
|
"-otxt",
|
||||||
"-of", CONFIGURATION["output_file"].replace(".txt", "")
|
"-of", CURENT_CONFIGURATION_LOCALE["output_file"].replace(".txt", "")
|
||||||
]
|
]
|
||||||
try:
|
try:
|
||||||
subprocess.run(whisper_cmd, check=True)
|
subprocess.run(whisper_cmd, check=True)
|
||||||
@@ -50,7 +53,7 @@ class WhisperWorker(QThread):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(CONFIGURATION["output_file"], "r") as f:
|
with open(CURENT_CONFIGURATION_LOCALE["output_file"], "r") as f:
|
||||||
raw_result = "\n".join(line.strip() for line in f.readlines())
|
raw_result = "\n".join(line.strip() for line in f.readlines())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Datei Fehler: {e}")
|
print(f"Datei Fehler: {e}")
|
||||||
@@ -60,24 +63,24 @@ class WhisperWorker(QThread):
|
|||||||
print("Whisper Transkript erhalten.")
|
print("Whisper Transkript erhalten.")
|
||||||
|
|
||||||
# --- An Ollama schicken ---
|
# --- An Ollama schicken ---
|
||||||
if CURRENT_PRESET["ollama"] != "disable":
|
if CURRENT_PRESET_LOCALE["ollama"] != "disable":
|
||||||
if isinstance(CURRENT_PRESET["ollama_prompt"], list):
|
if isinstance(CURRENT_PRESET_LOCALE["ollama_prompt"], list):
|
||||||
prompt = "\n".join(CURRENT_PRESET["ollama_prompt"])
|
prompt = "\n".join(CURRENT_PRESET_LOCALE["ollama_prompt"])
|
||||||
else:
|
else:
|
||||||
prompt = CURRENT_PRESET["ollama_prompt"]
|
prompt = CURRENT_PRESET_LOCALE["ollama_prompt"]
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"model": CURRENT_PRESET["ollama_model"],
|
"model": CURRENT_PRESET_LOCALE["ollama_model"],
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "system", "content": prompt},
|
{"role": "system", "content": prompt},
|
||||||
{"role": "user", "content": raw_result}
|
{"role": "user", "content": raw_result}
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"num_ctx": CURRENT_PRESET["ollama_context"]
|
"num_ctx": CURRENT_PRESET_LOCALE["ollama_context"]
|
||||||
},
|
},
|
||||||
"stream": False
|
"stream": False
|
||||||
}
|
}
|
||||||
ollama_endpoint = f"{CONFIGURATION['ollama_url']}:{CONFIGURATION['ollama_port']}/api/chat"
|
ollama_endpoint = f"{CURENT_CONFIGURATION_LOCALE['ollama_url']}:{CURENT_CONFIGURATION_LOCALE['ollama_port']}/api/chat"
|
||||||
response = requests.post(ollama_endpoint, json=payload)
|
response = requests.post(ollama_endpoint, json=payload)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -96,14 +99,14 @@ class WhisperWorker(QThread):
|
|||||||
print("Kein Ollama Prompt angegeben, nur Whisper Ergebnis verwendet.")
|
print("Kein Ollama Prompt angegeben, nur Whisper Ergebnis verwendet.")
|
||||||
|
|
||||||
# Ergebnis ins Clipboard kopieren
|
# Ergebnis ins Clipboard kopieren
|
||||||
if CURRENT_PRESET.get("mode") == "journal":
|
if CURRENT_PRESET_LOCALE.get("mode") == "journal":
|
||||||
today = datetime.date.today().strftime("%Y.%m.%d")
|
today = datetime.date.today().strftime("%Y.%m.%d")
|
||||||
journal_path = os.path.join(CONFIGURATION["journal_path"], f"{today} - {CURRENT_PRESET['journal_name']}.md")
|
journal_path = os.path.join(CURENT_CONFIGURATION_LOCALE["journal_path"], f"{today} - {CURRENT_PRESET_LOCALE['journal_name']}.md")
|
||||||
now = datetime.datetime.now().strftime("%H:%M:%S")
|
now = datetime.datetime.now().strftime("%H:%M:%S")
|
||||||
if not os.path.exists(journal_path):
|
if not os.path.exists(journal_path):
|
||||||
try:
|
try:
|
||||||
with open(journal_path, "w") as f:
|
with open(journal_path, "w") as f:
|
||||||
f.write(f"# {CURRENT_PRESET['journal_name']} - {today}\n\n")
|
f.write(f"# {CURRENT_PRESET_LOCALE['journal_name']} - {today}\n\n")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Journal Erstellungsfehler: {e}")
|
print(f"Journal Erstellungsfehler: {e}")
|
||||||
notify("Fehler", "Ein Fehler beim Erstellen des Journals ist aufgetreten!")
|
notify("Fehler", "Ein Fehler beim Erstellen des Journals ist aufgetreten!")
|
||||||
|
Reference in New Issue
Block a user