Spaces:
Runtime error
Runtime error
Commit
·
d852dec
1
Parent(s):
d668c41
Update app.py
Browse files
app.py
CHANGED
@@ -4,16 +4,26 @@ 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=transcribe_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)
|
@@ -48,22 +58,15 @@ with gr.Blocks() as demo:
|
|
48 |
D -->E[Answer]
|
49 |
""")
|
50 |
with gr.Column():
|
51 |
-
|
52 |
-
|
53 |
-
with gr.Row():
|
54 |
-
transcribe_btn = gr.Button("Trascribe")
|
55 |
with gr.Column():
|
56 |
-
|
57 |
-
|
58 |
-
with gr.Row():
|
59 |
-
out_yt_text = gr.Textbox()
|
60 |
with gr.Column():
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
ans_btn = gr.Button("Answer")
|
65 |
-
with gr.Row():
|
66 |
-
out_query = gr.outputs.Textbox()
|
67 |
|
68 |
|
69 |
transcribe_btn.click(fn=yt_transcribe, inputs=in_yt, outputs=[out_yt_html,out_yt_text])
|
|
|
4 |
from transformers import pipeline
|
5 |
from huggingface_hub import model_info
|
6 |
|
7 |
+
|
8 |
transcribe_model_ckpt = "openai/whisper-small"
|
9 |
lang = "en"
|
10 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
11 |
transcribe_pipe = pipeline(
|
12 |
task="automatic-speech-recognition",
|
13 |
model=transcribe_model_ckpt,
|
14 |
chunk_length_s=30,
|
15 |
+
device=device,
|
16 |
)
|
17 |
transcribe_pipe.model.config.forced_decoder_ids = transcribe_pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
|
18 |
|
19 |
+
def _return_yt_html_embed(yt_url):
|
20 |
+
video_id = yt_url.split("?v=")[-1]
|
21 |
+
HTML_str = (
|
22 |
+
f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
|
23 |
+
" </center>"
|
24 |
+
)
|
25 |
+
return HTML_str
|
26 |
+
|
27 |
def yt_transcribe(yt_url):
|
28 |
yt = pt.YouTube(yt_url)
|
29 |
html_embed_str = _return_yt_html_embed(yt_url)
|
|
|
58 |
D -->E[Answer]
|
59 |
""")
|
60 |
with gr.Column():
|
61 |
+
in_yt = gr.inputs.Textbox(lines=1, placeholder="Enter Youtube URL", label="YouTube URL")
|
62 |
+
transcribe_btn = gr.Button("Trascribe")
|
|
|
|
|
63 |
with gr.Column():
|
64 |
+
out_yt_html = gr.outputs.HTML()
|
65 |
+
out_yt_text = gr.Textbox()
|
|
|
|
|
66 |
with gr.Column():
|
67 |
+
in_query = gr.Textbox(lines=1, placeholder="What's your Question", label="Query")
|
68 |
+
ans_btn = gr.Button("Answer")
|
69 |
+
out_query = gr.outputs.Textbox()
|
|
|
|
|
|
|
70 |
|
71 |
|
72 |
transcribe_btn.click(fn=yt_transcribe, inputs=in_yt, outputs=[out_yt_html,out_yt_text])
|