Spaces:
Runtime error

videotranscript / app.py
santhoshkanna's picture
Update app.py
9babca7
Raw History Blame Contribute Delete
2.24 kB
import gradio as gr
import whisper_timestamped as whisper
from pytube import YouTube
from transformers import pipeline
loaded_model = whisper.load_model("base")
classifier = pipeline("zero-shot-classification")
def inference(link):
tot_mot = 0
tot_unmot = 0
yt = YouTube(link)
path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
options = whisper.DecodingOptions(without_timestamps=True)
results = loaded_model.transcribe(path)
output = []
for i, segment in enumerate(results['segments']):
start, end = segment['start'], segment['end']
#output.append(f"{i+1}")
output.append(f"00:00:{str(int(start)).replace('.', ',')} --> 00:00:{str(int(end)).replace('.', ',')}")
output.append(segment['text'].strip())
prd = predict(segment['text'].strip())
mot = prd['scores'][0]*100
unmot = prd['scores'][1]*100
tot_mot = tot_mot + prd['scores'][0]
tot_unmot = tot_unmot + prd['scores'][1]
output.append(f"Motivate - {mot} demotivate - {unmot}"+"\n")
i = i + 1
tot_mot = tot_mot/i
tot_unmot = tot_unmot/i
return ("\n".join(output), {"Motivate": tot_mot, "demotivate": tot_unmot})
def predict(str):
prd = classifier(
str,
candidate_labels=["motivate", "demotivate"],
)
return (prd)
def change_model(size):
loaded_model = whisper.load_model(size)
title="Video Transcription"
block = gr.Blocks()
with block:
gr.HTML(
"""
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
<div>
<h1>Video Transcription</h1>
</div>
</div>
"""
)
with gr.Group():
#with gr.Box():
# sz = gr.Dropdown(label="Model Size", choices=['base','small', 'medium', 'large'], value='base')
# sz.change(change_model, inputs=[sz], outputs=[])
link = gr.Textbox(label="YouTube Link")
text = gr.Textbox(
label="Transcription",
placeholder="Transcription Output",
lines=5)
label = gr.Label(
label="Percentage")
btn = gr.Button("Transcription")
btn.click(inference, inputs=[link], outputs=[text, label])
block.launch()