summarylogtreecommitdiffstats
path: root/0008-Fix-Download-models-to-data-dir-instead-of-local-dir.patch
blob: 89241273b3e36eb4919867d2e57369a7047a6daa (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From 3a9de5c0882290dc45c6fa6caa1da3a7d698bc11 Mon Sep 17 00:00:00 2001
From: Reyka Matthies <openglfreak@googlemail.com>
Date: Thu, 26 Mar 2026 06:07:59 +0100
Subject: [PATCH 08/12] [Fix] Download models to data dir instead of local dir

---
 src-python/model.py | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/src-python/model.py b/src-python/model.py
index 904c9012..18b99b50 100644
--- a/src-python/model.py
+++ b/src-python/model.py
@@ -160,14 +160,19 @@ class Model:
 
     def backwardCompatibleTranslatorCTranslate2ModelRenameWeightsDir(self):
         return backwardCompatibleRenameWeightsDir(config.PATH_LOCAL)
-        
+
     def checkTranslatorCTranslate2ModelWeight(self, weight_type:str):
-        return checkCTranslate2Weight(config.PATH_LOCAL, weight_type)
+        return (checkCTranslate2Weight(config.PATH_LOCAL, weight_type) or
+                checkCTranslate2Weight(config.PATH_DATA, weight_type))
 
     def changeTranslatorCTranslate2Model(self):
         self.ensure_initialized()
+        if checkCTranslate2Weight(config.PATH_LOCAL, config.CTRANSLATE2_WEIGHT_TYPE):
+            path = config.PATH_LOCAL
+        else:
+            path = config.PATH_DATA
         self.translator.changeCTranslate2Model(
-            path=config.PATH_LOCAL,
+            path=path,
             model_type=config.CTRANSLATE2_WEIGHT_TYPE,
             device=config.SELECTED_TRANSLATION_COMPUTE_DEVICE["device"],
             device_index=config.SELECTED_TRANSLATION_COMPUTE_DEVICE["device_index"],
@@ -175,10 +180,10 @@ class Model:
             )
 
     def downloadCTranslate2ModelWeight(self, weight_type, callback=None, end_callback=None):
-        return downloadCTranslate2Weight(config.PATH_LOCAL, weight_type, callback, end_callback)
+        return downloadCTranslate2Weight(config.PATH_DATA, weight_type, callback, end_callback)
 
     def downloadCTranslate2ModelTokenizer(self, weight_type):
-        return downloadCTranslate2Tokenizer(config.PATH_LOCAL, weight_type)
+        return downloadCTranslate2Tokenizer(config.PATH_DATA, weight_type)
 
     def isLoadedCTranslate2Model(self):
         self.ensure_initialized()
@@ -193,10 +198,11 @@ class Model:
         self.translator.setChangedTranslatorParameters(is_changed)
 
     def checkTranscriptionWhisperModelWeight(self, weight_type:str):
-        return checkWhisperWeight(config.PATH_LOCAL, weight_type)
+        return (checkWhisperWeight(config.PATH_LOCAL, weight_type) or
+                checkWhisperWeight(config.PATH_DATA, weight_type))
 
     def downloadWhisperModelWeight(self, weight_type, callback=None, end_callback=None):
-        return downloadWhisperWeight(config.PATH_LOCAL, weight_type, callback, end_callback)
+        return downloadWhisperWeight(config.PATH_DATA, weight_type, callback, end_callback)
 
     def resetKeywordProcessor(self):
         self.ensure_initialized()
@@ -390,7 +396,7 @@ class Model:
 
     def addTranslationHistory(self, source: str, text: str) -> None:
         """Add a message to translation context history.
-        
+
         Args:
             source: "chat" | "mic" | "speaker"
             text: message content
@@ -398,24 +404,24 @@ class Model:
         self.ensure_initialized()
         if not text or not text.strip():
             return
-        
+
         history_item = {
             "source": source,
             "text": text.strip(),
             "timestamp": datetime.now().isoformat(),
         }
         self.translation_history.append(history_item)
-        
+
         # 最大件数を超えた場合は古いものを削除
         if len(self.translation_history) > self.translation_history_max_items:
             self.translation_history = self.translation_history[-self.translation_history_max_items:]
-    
+
     def getTranslationHistory(self, max_items: int = None) -> list[dict]:
         """Get recent translation context history.
-        
+
         Args:
             max_items: Maximum number of items to return (newest first)
-        
+
         Returns:
             List of history items
         """
@@ -423,7 +429,7 @@ class Model:
         if max_items is None or max_items <= 0:
             return self.translation_history
         return self.translation_history[-max_items:]
-    
+
     def clearTranslationHistory(self) -> None:
         """Clear all translation context history."""
         self.ensure_initialized()
@@ -432,10 +438,10 @@ class Model:
     def getTranslate(self, translator_name, source_language, target_language, target_country, message):
         self.ensure_initialized()
         success_flag = False
-        
+
         # Get context history for LLM-based translators
         history = self.getTranslationHistory()
-        
+
         translation = self.translator.translate(
                         translator_name=translator_name,
                         weight_type=config.CTRANSLATE2_WEIGHT_TYPE,
@@ -745,7 +751,7 @@ class Model:
                 phrase_timeout=phrase_timeout,
                 max_phrases=config.MIC_MAX_PHRASES,
                 transcription_engine=config.SELECTED_TRANSCRIPTION_ENGINE,
-                root=config.PATH_LOCAL,
+                root=config.PATH_DATA,
                 whisper_weight_type=config.WHISPER_WEIGHT_TYPE,
                 device=config.SELECTED_TRANSCRIPTION_COMPUTE_DEVICE["device"],
                 device_index=config.SELECTED_TRANSCRIPTION_COMPUTE_DEVICE["device_index"],
@@ -940,7 +946,7 @@ class Model:
                 phrase_timeout=phrase_timeout,
                 max_phrases=config.SPEAKER_MAX_PHRASES,
                 transcription_engine=config.SELECTED_TRANSCRIPTION_ENGINE,
-                root=config.PATH_LOCAL,
+                root=config.PATH_DATA,
                 whisper_weight_type=config.WHISPER_WEIGHT_TYPE,
                 device=config.SELECTED_TRANSCRIPTION_COMPUTE_DEVICE["device"],
                 device_index=config.SELECTED_TRANSCRIPTION_COMPUTE_DEVICE["device_index"],
-- 
2.53.0