Redmind commited on
Commit
48fa0fc
·
verified ·
1 Parent(s): 7d26c44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -31,7 +31,6 @@ iface = gr.Interface(
31
  )
32
 
33
  iface.launch()
34
- """
35
  from transformers import pipeline, MBartTokenizer
36
  import gradio as gr
37
 
@@ -48,3 +47,39 @@ def convert_to_casual_hindi(text):
48
  # Gradio interface for deployment in Hugging Face Spaces
49
  iface = gr.Interface(fn=convert_to_casual_hindi, inputs="text", outputs="text", title="Formal to Casual Hindi Converter")
50
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  )
32
 
33
  iface.launch()
 
34
  from transformers import pipeline, MBartTokenizer
35
  import gradio as gr
36
 
 
47
  # Gradio interface for deployment in Hugging Face Spaces
48
  iface = gr.Interface(fn=convert_to_casual_hindi, inputs="text", outputs="text", title="Formal to Casual Hindi Converter")
49
  iface.launch()
50
+ """
51
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
52
+ import gradio as gr
53
+
54
+ # Load a multilingual T5 model pre-trained for Hindi
55
+ model_name = "google/mt5-base" # mT5-base works well for Hindi
56
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
57
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
58
+
59
+ def formal_to_casual_hindi(input_text):
60
+ """
61
+ Converts formal Hindi text into conversational Hindi using mT5.
62
+ """
63
+ # Prepare the input for conversational reformulation
64
+ prompt = f"Convert the following formal Hindi text to casual spoken Hindi: {input_text}"
65
+
66
+ # Tokenize input
67
+ input_ids = tokenizer.encode(prompt, return_tensors="pt")
68
+
69
+ # Generate conversational text
70
+ outputs = model.generate(input_ids, max_length=128, num_beams=5, early_stopping=True)
71
+
72
+ # Decode the output
73
+ casual_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
74
+ return casual_text
75
+
76
+ # Gradio interface for the deployment
77
+ iface = gr.Interface(
78
+ fn=formal_to_casual_hindi,
79
+ inputs="text",
80
+ outputs="text",
81
+ title="Formal to Casual Hindi Converter",
82
+ description="Convert formal Hindi text into conversational Hindi using AI."
83
+ )
84
+
85
+ iface.launch()