Upload handler.py with huggingface_hub
Browse files- handler.py +5 -4
handler.py
CHANGED
|
@@ -52,13 +52,14 @@ class EndpointHandler:
|
|
| 52 |
|
| 53 |
if is_custom_prompt:
|
| 54 |
# Custom prompt format for unsupported languages
|
| 55 |
-
#
|
| 56 |
-
prompt = f"<start_of_turn>user\n{target_lang} {text}<end_of_turn>\n<start_of_turn>model\n"
|
| 57 |
-
|
| 58 |
prompt,
|
| 59 |
return_tensors="pt",
|
| 60 |
add_special_tokens=True
|
| 61 |
-
)
|
|
|
|
| 62 |
else:
|
| 63 |
# Standard language code: use structured message format
|
| 64 |
messages = [
|
|
|
|
| 52 |
|
| 53 |
if is_custom_prompt:
|
| 54 |
# Custom prompt format for unsupported languages
|
| 55 |
+
# Add explicit instruction to return ONLY the translation
|
| 56 |
+
prompt = f"<start_of_turn>user\n{target_lang} Output only the translation, no explanations.\n\n{text}<end_of_turn>\n<start_of_turn>model\n"
|
| 57 |
+
tokenized = self.processor.tokenizer(
|
| 58 |
prompt,
|
| 59 |
return_tensors="pt",
|
| 60 |
add_special_tokens=True
|
| 61 |
+
)
|
| 62 |
+
inputs = {k: v.to(self.model.device) for k, v in tokenized.items()}
|
| 63 |
else:
|
| 64 |
# Standard language code: use structured message format
|
| 65 |
messages = [
|