umarasif commited on
Commit
71ea06a
1 Parent(s): 24ac2f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import torch
2
  from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
  import gradio as gr
@@ -42,13 +43,13 @@ def extract_audio_from_video(video_path, audio_output_path):
42
  def speech_to_text(input_file):
43
  try:
44
  if input_file.name.endswith((".mp4", ".avi", ".mov")):
45
- audio_file_path = extract_audio_from_video(input_file.name, "temp_audio.mp3")
46
  if audio_file_path:
47
  result = pipe(audio_file_path)
48
- return result[0]["transcription"]
49
  else:
50
- result = pipe(input_file.read())
51
- return result[0]["transcription"]
52
  except Exception as e:
53
  return f"Error: {str(e)}"
54
 
 
1
+ # gradio app
2
  import torch
3
  from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
4
  import gradio as gr
 
43
  def speech_to_text(input_file):
44
  try:
45
  if input_file.name.endswith((".mp4", ".avi", ".mov")):
46
+ audio_file_path = extract_audio_from_video(input_file, "temp_audio.mp3")
47
  if audio_file_path:
48
  result = pipe(audio_file_path)
49
+ return result["text"]
50
  else:
51
+ result = pipe(input_file)
52
+ return result["text"]
53
  except Exception as e:
54
  return f"Error: {str(e)}"
55