SmitaGautam commited on
Commit
e6604f3
·
verified ·
1 Parent(s): bd9cf85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -106,7 +106,7 @@ def transliterate(word):
106
  # TinyLLaMA prediction
107
  if has_llm:
108
  try:
109
- prompt = f"Transliterate the following English word to Hindi (Devanagari script).\nEnglish word: {word}\nHindi transliteration:"
110
  inputs = llm_tokenizer(prompt, return_tensors="pt").to(device)
111
 
112
  with torch.no_grad():
@@ -122,6 +122,14 @@ def transliterate(word):
122
 
123
  generated = llm_tokenizer.decode(output_ids[0], skip_special_tokens=True)
124
  llm_pred = generated.replace(prompt, "").strip()
 
 
 
 
 
 
 
 
125
  except Exception as e:
126
  llm_pred = f"Error: {str(e)[:50]}"
127
  else:
 
106
  # TinyLLaMA prediction
107
  if has_llm:
108
  try:
109
+ prompt = f"Output only the Hindi Devanagari transliteration of: {word}"
110
  inputs = llm_tokenizer(prompt, return_tensors="pt").to(device)
111
 
112
  with torch.no_grad():
 
122
 
123
  generated = llm_tokenizer.decode(output_ids[0], skip_special_tokens=True)
124
  llm_pred = generated.replace(prompt, "").strip()
125
+
126
+ # Remove common prefixes and colons
127
+ for prefix in ["Devanagari script:", "Hindi transliteration:", "Transliteration:", "Translation:"]:
128
+ llm_pred = llm_pred.replace(prefix, "").strip()
129
+
130
+ # Remove leading/trailing colons and whitespace
131
+ llm_pred = llm_pred.lstrip(":").strip()
132
+
133
  except Exception as e:
134
  llm_pred = f"Error: {str(e)[:50]}"
135
  else: