Spaces:
Sleeping
Sleeping
File size: 2,108 Bytes
86c0a67 148f6b6 73d45a9 148f6b6 73d45a9 148f6b6 73d45a9 148f6b6 86c0a67 ca3c027 60eda07 1bbfa19 60eda07 1bbfa19 60eda07 86c0a67 |
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 |
import gradio as gr
import torch
import pytube as pt
from transformers import pipeline
from huggingface_hub import model_info
transcribe_model_ckpt = "openai/whisper-small"
lang = "en"
transcribe_pipe = pipeline(
task="automatic-speech-recognition",
model=transcribe_model_ckpt,
chunk_length_s=30,
)
transcribe_pipe.model.config.forced_decoder_ids = transcribe_pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
def yt_transcribe(yt_url):
yt = pt.YouTube(yt_url)
html_embed_str = _return_yt_html_embed(yt_url)
stream = yt.streams.filter(only_audio=True)[0]
stream.download(filename="audio.mp3")
text = transcribe_pipe("audio.mp3")["text"]
return html_embed_str, text
qa_model_ckpt = "deepset/tinyroberta-squad2"
qa_pipe = pipeline('question-answering', model=qa_model_ckpt, tokenizer=qa_model_ckpt)
def get_answer(query,context):
QA_input = {
'question': query,
'context': context
}
res = qa_pipe(QA_input)["answer"]
return res
with gr.Blocks() as demo:
gr.Markdown("<h1><center>Youtube-QA</center></h1>")
gr.Markdown("<h3>Ask questions from your youtube video of choice</h3>")
gr.Markdown("""mermaid
graph LR
A[Youtube-audio] -->B(openai-whisper)
B -->C(Trascription)
C -->|Query| D(QA-model)
D -->E[Answer]
""")
with gr.Column():
with gr.Row():
in_yt = gr.Textbox(lines=1, placeholder="Enter Youtube URL", label="YouTube URL")
transcribe_btn = gr.Button("Trascribe")
with gr.Column():
with gr.Row():
out_yt = ["html", "text"],
with gr.Column():
with gr.Row():
in_query = gr.Textbox(lines=1, placeholder="What's your Question", label="Query")
ans_btn = gr.Button("Answer")
out_query = ["text"]
ans_btn.click(fn=get_answer, inputs=[in_query,out_yt["text"]], outputs=out_query)
transcribe_btn.click(fn=yt_transcribe, inputs=in_yt, outputs=out_yt)
demo.launch() |