ankitklakra commited on
Commit
d0c5307
·
verified ·
1 Parent(s): c2f19a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -75,15 +75,22 @@ def process_translation(text, audio_input, direction, is_hinglish):
75
  original_text = speech_to_text(audio_input) if audio_input else text
76
  if not original_text: return "", "", None
77
 
78
- # 2. Handle Hinglish (NEW FEATURE)
79
- # Only applies if translating TO Kurukh (User typing Hindi in English letters)
80
  if direction == "Hindi -> Kurukh" and is_hinglish:
81
  original_text = transliterate_to_hindi(original_text)
82
 
83
- # 3. Translate
84
  target_pipeline = pipe_k2h if direction == "Kurukh -> Hindi" else pipe_h2k
85
  try:
86
- results = target_pipeline(original_text, max_length=128)
 
 
 
 
 
 
 
 
87
  translated_text = results[0]['generated_text']
88
  except Exception as e:
89
  return str(e), "", None
@@ -93,7 +100,6 @@ def process_translation(text, audio_input, direction, is_hinglish):
93
  if direction == "Kurukh -> Hindi":
94
  audio_output = text_to_speech(translated_text, "hi")
95
 
96
- # Return: (Updated Input Box), (Translation), (Audio)
97
  return original_text, translated_text, audio_output
98
 
99
  # --- THE UI ---
 
75
  original_text = speech_to_text(audio_input) if audio_input else text
76
  if not original_text: return "", "", None
77
 
78
+ # 2. Handle Hinglish
 
79
  if direction == "Hindi -> Kurukh" and is_hinglish:
80
  original_text = transliterate_to_hindi(original_text)
81
 
82
+ # 3. Translate
83
  target_pipeline = pipe_k2h if direction == "Kurukh -> Hindi" else pipe_h2k
84
  try:
85
+
86
+ results = target_pipeline(
87
+ original_text,
88
+ max_length=128,
89
+ num_beams=5,
90
+ no_repeat_ngram_size=2,
91
+ repetition_penalty=2.0,
92
+ early_stopping=True
93
+ )
94
  translated_text = results[0]['generated_text']
95
  except Exception as e:
96
  return str(e), "", None
 
100
  if direction == "Kurukh -> Hindi":
101
  audio_output = text_to_speech(translated_text, "hi")
102
 
 
103
  return original_text, translated_text, audio_output
104
 
105
  # --- THE UI ---