cptsubtext commited on
Commit
c75a5bc
·
1 Parent(s): 5237203

add option to translate

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -22,6 +22,9 @@ uploaded_file = st.file_uploader("Upload Audio File", type=["mp3", "wav", "mov"]
22
  use_free_tier = st.checkbox("Free Tier (Max 2 minutes)")
23
  api_token = st.text_input("API Token (Unlimited)")
24
 
 
 
 
25
  # Model selection
26
  model_size = st.selectbox("Model Size", ("tiny", "base", "small", "medium"))
27
 
@@ -45,6 +48,12 @@ def transcribe_to_subtitle(audio_bytes, model_name):
45
  except Exception as e:
46
  return {"error": f"Error during transcription: {str(e)}"}
47
 
 
 
 
 
 
 
48
  captions = pysrt.open("audio.srt")
49
  for caption in captions:
50
  print(caption.start)
 
22
  use_free_tier = st.checkbox("Free Tier (Max 2 minutes)")
23
  api_token = st.text_input("API Token (Unlimited)")
24
 
25
+ # Should we translate to english?
26
+ translate = st.checkbox("Would you like a translation to english?")
27
+
28
  # Model selection
29
  model_size = st.selectbox("Model Size", ("tiny", "base", "small", "medium"))
30
 
 
48
  except Exception as e:
49
  return {"error": f"Error during transcription: {str(e)}"}
50
 
51
+ if translate:
52
+ # Get text from speech for subtitles from audio file
53
+ translation = model.transcribe(audio_bytes, verbose=True, task = 'translate')
54
+ english_output = translation.text
55
+ st.markdown(english_output, unsafe_allow_html=True)
56
+
57
  captions = pysrt.open("audio.srt")
58
  for caption in captions:
59
  print(caption.start)