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( """