Spaces:
Build error
Build error
Upload utils/gemma_translation.py with huggingface_hub
Browse files- utils/gemma_translation.py +9 -23
utils/gemma_translation.py
CHANGED
|
@@ -16,7 +16,8 @@ import contextlib
|
|
| 16 |
|
| 17 |
# Import configuration defaults
|
| 18 |
from config import DEFAULT_CONFIG
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
@contextlib.contextmanager
|
| 22 |
def suppress_stdout_stderr():
|
|
@@ -49,7 +50,8 @@ logging.basicConfig(level=logging.INFO)
|
|
| 49 |
logger = logging.getLogger(__name__)
|
| 50 |
|
| 51 |
# Model configuration from config
|
| 52 |
-
ORIGINAL_MODEL_PATH = os.path.join("local_llms", "gemma-3-12b-it-Q4_K_M.gguf")
|
|
|
|
| 53 |
MODEL_DIR = os.path.join("local_llms", "instances")
|
| 54 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 55 |
|
|
@@ -123,28 +125,12 @@ class GemmaTranslator:
|
|
| 123 |
|
| 124 |
# Create a session-specific model path
|
| 125 |
self.model_path = self._get_session_model_path()
|
| 126 |
-
|
| 127 |
def _get_session_model_path(self):
|
| 128 |
-
"""
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
# If the model file doesn't exist yet, create it by copying the original
|
| 134 |
-
if not os.path.exists(session_model_path):
|
| 135 |
-
if not os.path.exists(ORIGINAL_MODEL_PATH):
|
| 136 |
-
raise FileNotFoundError(f"Original model file not found: {ORIGINAL_MODEL_PATH}")
|
| 137 |
-
|
| 138 |
-
logger.info(f"Creating session-specific model file for {self.session_id}")
|
| 139 |
-
try:
|
| 140 |
-
shutil.copy2(ORIGINAL_MODEL_PATH, session_model_path)
|
| 141 |
-
logger.info(f"Created session model at {session_model_path}")
|
| 142 |
-
except Exception as e:
|
| 143 |
-
logger.error(f"Failed to create session model: {str(e)}")
|
| 144 |
-
# Fallback to original model if copy fails
|
| 145 |
-
return ORIGINAL_MODEL_PATH
|
| 146 |
-
|
| 147 |
-
return session_model_path
|
| 148 |
|
| 149 |
|
| 150 |
def load_model(self,
|
|
|
|
| 16 |
|
| 17 |
# Import configuration defaults
|
| 18 |
from config import DEFAULT_CONFIG
|
| 19 |
+
from utils.model_bootstrap import ensure_gemma
|
| 20 |
+
MODEL_PATH = ensure_gemma()
|
| 21 |
|
| 22 |
@contextlib.contextmanager
|
| 23 |
def suppress_stdout_stderr():
|
|
|
|
| 50 |
logger = logging.getLogger(__name__)
|
| 51 |
|
| 52 |
# Model configuration from config
|
| 53 |
+
# ORIGINAL_MODEL_PATH = os.path.join("local_llms", "gemma-3-12b-it-Q4_K_M.gguf")
|
| 54 |
+
ORIGINAL_MODEL_PATH = MODEL_PATH
|
| 55 |
MODEL_DIR = os.path.join("local_llms", "instances")
|
| 56 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 57 |
|
|
|
|
| 125 |
|
| 126 |
# Create a session-specific model path
|
| 127 |
self.model_path = self._get_session_model_path()
|
| 128 |
+
|
| 129 |
def _get_session_model_path(self):
|
| 130 |
+
"""Use the single shared GGUF file instead of copying per session."""
|
| 131 |
+
if not os.path.exists(ORIGINAL_MODEL_PATH):
|
| 132 |
+
raise FileNotFoundError(f"Original model file not found: {ORIGINAL_MODEL_PATH}")
|
| 133 |
+
return ORIGINAL_MODEL_PATH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
def load_model(self,
|