parthnuwal7 commited on
Commit
ac8959c
·
1 Parent(s): 9b1ad5f

Changed translation model

Browse files
Files changed (1) hide show
  1. src/utils/data_processor.py +5 -9
src/utils/data_processor.py CHANGED
@@ -86,7 +86,8 @@ class TranslationService:
86
 
87
  def __init__(self):
88
  self.api_token = self._get_hf_token()
89
- self.translation_model = "facebook/m2m100_418M"
 
90
  self.base_url = "https://api-inference.huggingface.co/models"
91
  logger.info("Initialized HF Inference API for translation")
92
 
@@ -115,19 +116,14 @@ class TranslationService:
115
  headers = {"Authorization": f"Bearer {self.api_token}"}
116
  url = f"{self.base_url}/{self.translation_model}"
117
 
118
- # Format input for M2M100
119
- payload = {
120
- "inputs": text,
121
- "parameters": {
122
- "src_lang": source_lang,
123
- "tgt_lang": target_lang
124
- }
125
- }
126
 
127
  response = requests.post(url, headers=headers, json=payload, timeout=30)
128
 
129
  if response.status_code == 200:
130
  result = response.json()
 
131
  if isinstance(result, list) and len(result) > 0:
132
  return result[0].get("translation_text", text)
133
 
 
86
 
87
  def __init__(self):
88
  self.api_token = self._get_hf_token()
89
+ # Using Helsinki-NLP model - better Inference API support for Hindi→English
90
+ self.translation_model = "Helsinki-NLP/opus-mt-hi-en"
91
  self.base_url = "https://api-inference.huggingface.co/models"
92
  logger.info("Initialized HF Inference API for translation")
93
 
 
116
  headers = {"Authorization": f"Bearer {self.api_token}"}
117
  url = f"{self.base_url}/{self.translation_model}"
118
 
119
+ # Simplified payload for Helsinki-NLP models
120
+ payload = {"inputs": text}
 
 
 
 
 
 
121
 
122
  response = requests.post(url, headers=headers, json=payload, timeout=30)
123
 
124
  if response.status_code == 200:
125
  result = response.json()
126
+ # Helsinki models return: [{"translation_text": "..."}]
127
  if isinstance(result, list) and len(result) > 0:
128
  return result[0].get("translation_text", text)
129