BurhaanZargar commited on
Commit
4399d89
·
1 Parent(s): 2a7702f
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -1,4 +1,3 @@
1
- #app.py
2
  import gradio as gr
3
  import torch
4
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
@@ -7,7 +6,11 @@ import requests
7
  from datetime import datetime
8
  import tempfile
9
  from gtts import gTTS
 
 
10
 
 
 
11
 
12
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
13
 
@@ -125,14 +128,14 @@ def transcribe_audio(audio_path):
125
  # --- Handle audio translation ---
126
  def handle_audio_translation(audio_path, direction):
127
  if direction != "en_to_ks":
128
- return "⚠️ Audio input is only supported for English to Kashmiri.", "", None
129
 
130
  transcription, error = transcribe_audio(audio_path)
131
  if error:
132
- return error, "", None
133
 
134
- translated, _ = translate(transcription, direction)
135
- return "", transcription, translated
136
 
137
  # --- Switch UI direction ---
138
  def switch_direction(direction, input_text_val, output_text_val):
@@ -143,7 +146,13 @@ def switch_direction(direction, input_text_val, output_text_val):
143
 
144
  # === Gradio Interface ===
145
  with gr.Blocks() as interface:
146
- gr.HTML("<h2 style='text-align:center;'>English ↔ Kashmiri Translator</h2>")
 
 
 
 
 
 
147
  translation_direction = gr.State(value="en_to_ks")
148
 
149
  with gr.Row():
@@ -198,7 +207,7 @@ with gr.Blocks() as interface:
198
  stt_button.click(
199
  fn=handle_audio_translation,
200
  inputs=[audio_input, translation_direction],
201
- outputs=[save_status, input_text, output_text]
202
  )
203
 
204
  if __name__ == "__main__":
 
 
1
  import gradio as gr
2
  import torch
3
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
 
6
  from datetime import datetime
7
  import tempfile
8
  from gtts import gTTS
9
+ import os
10
+ import logging
11
 
12
+ # Configure logging
13
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
14
 
15
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
16
 
 
128
  # --- Handle audio translation ---
129
  def handle_audio_translation(audio_path, direction):
130
  if direction != "en_to_ks":
131
+ return "⚠️ Audio input is only supported for English to Kashmiri.", "", "", None
132
 
133
  transcription, error = transcribe_audio(audio_path)
134
  if error:
135
+ return error, "", "", None
136
 
137
+ translated, _ = translate(transcription, direction, generate_tts=False)
138
+ return "", transcription, translated, None
139
 
140
  # --- Switch UI direction ---
141
  def switch_direction(direction, input_text_val, output_text_val):
 
146
 
147
  # === Gradio Interface ===
148
  with gr.Blocks() as interface:
149
+ gr.HTML("""
150
+ <div style="display: flex; justify-content: space-between; align-items: center; padding: 10px;">
151
+ <img src="https://raw.githubusercontent.com/BurhaanRasheedZargar/Images/211321a234613a9c3dd944fe9367cf13d1386239/assets/left_logo.png" style="height:150px; width:auto;">
152
+ <h2 style="margin: 0; text-align: center;">English ↔ Kashmiri Translator</h2>
153
+ <img src="https://raw.githubusercontent.com/BurhaanRasheedZargar/Images/77797f7f7cbee328fa0f9d31cf3e290441e04cd3/assets/right_logo.png">
154
+ </div>
155
+ """)
156
  translation_direction = gr.State(value="en_to_ks")
157
 
158
  with gr.Row():
 
207
  stt_button.click(
208
  fn=handle_audio_translation,
209
  inputs=[audio_input, translation_direction],
210
+ outputs=[save_status, input_text, output_text, audio_output]
211
  )
212
 
213
  if __name__ == "__main__":