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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -9
app.py CHANGED
@@ -106,7 +106,7 @@ def transliterate(word):
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,14 +122,7 @@ def transliterate(word):
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:
 
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
 
123
  generated = llm_tokenizer.decode(output_ids[0], skip_special_tokens=True)
124
  llm_pred = generated.replace(prompt, "").strip()
125
+ llm_pred = ''.join(c for c in llm_pred if not (c.isascii() and c.isalpha()) and c.strip())
 
 
 
 
 
 
 
126
  except Exception as e:
127
  llm_pred = f"Error: {str(e)[:50]}"
128
  else: