aitextvideo commited on
Commit
72577f4
·
verified ·
1 Parent(s): 9108ebd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,15 +1,19 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- def video_to_text(video_path):
5
- asr = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=-1)
6
- text = asr(video_path)["text"]
 
 
 
 
7
  return text
8
 
9
  with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
10
  gr.Markdown("# 🎥 Video-to-Text AI Tool\nUpload a video and get the transcript instantly.")
11
 
12
- video_input = gr.Video(label="Upload Video", type="filepath")
13
  transcript_output = gr.Textbox(label="Transcript", lines=10)
14
 
15
  btn = gr.Button("Generate Transcript")
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the ASR model once (faster, avoids reloading each time)
5
+ asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
6
+
7
+ def video_to_text(video_file):
8
+ if video_file is None:
9
+ return "Please upload a video file."
10
+ text = asr(video_file)["text"]
11
  return text
12
 
13
  with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
14
  gr.Markdown("# 🎥 Video-to-Text AI Tool\nUpload a video and get the transcript instantly.")
15
 
16
+ video_input = gr.Video(label="Upload Video")
17
  transcript_output = gr.Textbox(label="Transcript", lines=10)
18
 
19
  btn = gr.Button("Generate Transcript")