Spaces:
Running
on
Zero
Running
on
Zero
Update carebridge_client.py
Browse files- carebridge_client.py +12 -13
carebridge_client.py
CHANGED
|
@@ -22,20 +22,8 @@ class CareBridgeTranslator:
|
|
| 22 |
self.processor = None
|
| 23 |
print(f"[SIMBOTI] Translator initialized. Model will load on first use.")
|
| 24 |
|
| 25 |
-
def _load_model(self):
|
| 26 |
-
if self.model is None:
|
| 27 |
-
print(f"[SIMBOTI] Loading model {self.model_id}...")
|
| 28 |
-
self.processor = AutoProcessor.from_pretrained(self.model_id)
|
| 29 |
-
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 30 |
-
self.model_id,
|
| 31 |
-
device_map=self.device,
|
| 32 |
-
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
|
| 33 |
-
)
|
| 34 |
-
print("[SIMBOTI] Model loaded successfully.")
|
| 35 |
-
|
| 36 |
# Top 10 NHS Languages Mapping (ISO 639-1)
|
| 37 |
self.LANG_MAP = {
|
| 38 |
-
|
| 39 |
"English": "en",
|
| 40 |
"Polish": "pl",
|
| 41 |
"Romanian": "ro",
|
|
@@ -49,6 +37,17 @@ class CareBridgeTranslator:
|
|
| 49 |
"Italian": "it"
|
| 50 |
}
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def translate_text(self, text, source_lang_name, target_lang_name):
|
| 53 |
"""
|
| 54 |
Translate text ensuring patient data stays local.
|
|
@@ -184,4 +183,4 @@ class CareBridgeTranslator:
|
|
| 184 |
# Simple Verification Test if run directly
|
| 185 |
if __name__ == "__main__":
|
| 186 |
translator = CareBridgeTranslator()
|
| 187 |
-
print("Test 1 (Text):", translator.translate_text("Where does it hurt?", "English", "Polish"))
|
|
|
|
| 22 |
self.processor = None
|
| 23 |
print(f"[SIMBOTI] Translator initialized. Model will load on first use.")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Top 10 NHS Languages Mapping (ISO 639-1)
|
| 26 |
self.LANG_MAP = {
|
|
|
|
| 27 |
"English": "en",
|
| 28 |
"Polish": "pl",
|
| 29 |
"Romanian": "ro",
|
|
|
|
| 37 |
"Italian": "it"
|
| 38 |
}
|
| 39 |
|
| 40 |
+
def _load_model(self):
|
| 41 |
+
if self.model is None:
|
| 42 |
+
print(f"[SIMBOTI] Loading model {self.model_id}...")
|
| 43 |
+
self.processor = AutoProcessor.from_pretrained(self.model_id)
|
| 44 |
+
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 45 |
+
self.model_id,
|
| 46 |
+
device_map=self.device,
|
| 47 |
+
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32
|
| 48 |
+
)
|
| 49 |
+
print("[SIMBOTI] Model loaded successfully.")
|
| 50 |
+
|
| 51 |
def translate_text(self, text, source_lang_name, target_lang_name):
|
| 52 |
"""
|
| 53 |
Translate text ensuring patient data stays local.
|
|
|
|
| 183 |
# Simple Verification Test if run directly
|
| 184 |
if __name__ == "__main__":
|
| 185 |
translator = CareBridgeTranslator()
|
| 186 |
+
print("Test 1 (Text):", translator.translate_text("Where does it hurt?", "English", "Polish"))
|