skmdud commited on
Commit
5a57a8a
·
verified ·
1 Parent(s): 63f9b39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,18 +1,23 @@
1
  import gradio as gr
2
- from indic_transliteration import sanscript
3
- from indic_transliteration.sanscript import transliterate
4
 
5
- def translit_text(text):
6
- # Roman Hindi से Hindi (Devanagari) में बदलना
7
- hindi_text = transliterate(text, sanscript.ITRANS, sanscript.DEVANAGARI)
 
 
 
 
 
 
8
  return hindi_text
9
 
10
  demo = gr.Interface(
11
- fn=translit_text,
12
  inputs="text",
13
  outputs="text",
14
  title="🔤 Roman Hindi → Hindi Transliteration Demo",
15
- description="Type in Roman Hindi (like: mujhe pyar hai) and see it in Devanagari Hindi."
16
  )
17
 
18
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
 
3
 
4
+ # Hinglish to Hindi Transliteration model (ai4bharat)
5
+ model_name = "ai4bharat/indictrans2-en-indic-1B"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name, trust_remote_code=True)
8
+
9
+ def transliterate_text(text):
10
+ inputs = tokenizer(text, return_tensors="pt")
11
+ outputs = model.generate(**inputs, max_length=128)
12
+ hindi_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
  return hindi_text
14
 
15
  demo = gr.Interface(
16
+ fn=transliterate_text,
17
  inputs="text",
18
  outputs="text",
19
  title="🔤 Roman Hindi → Hindi Transliteration Demo",
20
+ description="Type in Roman Hindi (like: mujhe pyar hai) and see it in proper Hindi."
21
  )
22
 
23
  if __name__ == "__main__":