frogcho123 commited on
Commit
b2604a4
1 Parent(s): 0053c85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
4
  import whisper
5
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
  from gtts import gTTS
7
- from IPython.display import Audio
8
 
9
  # Load the models and tokenizer
10
  whisper_model = whisper.load_model("base")
@@ -40,7 +40,10 @@ def translate_audio(input_file, to_lang):
40
  # Load audio data from file
41
  audio_data = open(temp_output_file, "rb").read()
42
 
43
- return Audio(audio_data)
 
 
 
44
 
45
  def translate_audio_interface(input_file, to_lang):
46
  return translate_audio(input_file, to_lang)
@@ -48,7 +51,7 @@ def translate_audio_interface(input_file, to_lang):
48
  iface = gr.Interface(
49
  fn=translate_audio_interface,
50
  inputs=["file", "text"],
51
- outputs="audio",
52
  title="Audio Translation",
53
  description="Upload an MP3 file and select the target language for translation.",
54
  examples=[
@@ -57,4 +60,5 @@ iface = gr.Interface(
57
  ]
58
  )
59
 
60
- iface.launch(debug = True)
 
 
4
  import whisper
5
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
6
  from gtts import gTTS
7
+ import base64
8
 
9
  # Load the models and tokenizer
10
  whisper_model = whisper.load_model("base")
 
40
  # Load audio data from file
41
  audio_data = open(temp_output_file, "rb").read()
42
 
43
+ # Convert audio data to Base64 string
44
+ audio_base64 = base64.b64encode(audio_data).decode("utf-8")
45
+
46
+ return audio_base64
47
 
48
  def translate_audio_interface(input_file, to_lang):
49
  return translate_audio(input_file, to_lang)
 
51
  iface = gr.Interface(
52
  fn=translate_audio_interface,
53
  inputs=["file", "text"],
54
+ outputs="text",
55
  title="Audio Translation",
56
  description="Upload an MP3 file and select the target language for translation.",
57
  examples=[
 
60
  ]
61
  )
62
 
63
+ iface.launch()
64
+