Spaces:
Runtime error
Runtime error
Commit
·
148f6b6
1
Parent(s):
86c0a67
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,41 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
def update(name):
|
| 3 |
return f"Welcome to Gradio, {name}!"
|
| 4 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import pytube as pt
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from huggingface_hub import model_info
|
| 6 |
+
|
| 7 |
+
transcribe_model_ckpt = "openai/whisper-small"
|
| 8 |
+
lang = "en"
|
| 9 |
+
|
| 10 |
+
transcribe_pipe = pipeline(
|
| 11 |
+
task="automatic-speech-recognition",
|
| 12 |
+
model=model_ckpt,
|
| 13 |
+
chunk_length_s=30,
|
| 14 |
+
)
|
| 15 |
+
transcribe_pipe.model.config.forced_decoder_ids = transcribe_pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
|
| 16 |
+
|
| 17 |
+
def yt_transcribe(yt_url):
|
| 18 |
+
yt = pt.YouTube(yt_url)
|
| 19 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
| 20 |
+
stream = yt.streams.filter(only_audio=True)[0]
|
| 21 |
+
stream.download(filename="audio.mp3")
|
| 22 |
+
|
| 23 |
+
text = transcribe_pipe("audio.mp3")["text"]
|
| 24 |
+
|
| 25 |
+
return html_embed_str, text
|
| 26 |
+
|
| 27 |
+
qa_model_ckpt = "deepset/tinyroberta-squad2"
|
| 28 |
+
qa_pipe = pipeline('question-answering', model=model_ckpt, tokenizer=model_ckpt)
|
| 29 |
+
|
| 30 |
+
def get_answer(query,context):
|
| 31 |
+
QA_input = {
|
| 32 |
+
'question': query,
|
| 33 |
+
'context': context
|
| 34 |
+
}
|
| 35 |
+
res = nlp(QA_input)["answer"]
|
| 36 |
+
return res
|
| 37 |
+
|
| 38 |
+
|
| 39 |
def update(name):
|
| 40 |
return f"Welcome to Gradio, {name}!"
|
| 41 |
|