Spaces:
Runtime error
Runtime error
File size: 2,241 Bytes
98f95f7 3a134b0 98f95f7 1753d28 98f95f7 734a175 98f95f7 9babca7 98f95f7 d6f363f f9b1d69 d6f363f 9babca7 98f95f7 f9b1d69 98f95f7 9babca7 3a134b0 98f95f7 9babca7 98f95f7 9babca7 98f95f7 b3c32e8 315973c 9babca7 1d50e19 315973c 9babca7 315973c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | 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() |