File size: 1,227 Bytes
c510d8a
8863a3f
 
d6a85e3
 
c510d8a
 
95dc466
12c5b62
 
c510d8a
 
 
12c5b62
c510d8a
3287afb
12c5b62
de32888
f213cf3
12c5b62
3287afb
d4e618e
 
70ebc27
 
 
d4e618e
70ebc27
d4e618e
 
 
 
 
 
 
 
12c5b62
d6a85e3
70ebc27
758e43f
d6a85e3
12c5b62
 
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

from util import load_model
from util import pipeline

import gradio as gr
cp_aug = 'minnehwg/finetune-newwiki-summarization-ver-augmented2'


def get_model(cp):
    checkpoint = cp
    tokenizer, model = load_model(checkpoint)
    return tokenizer, model

tokenizer, model = get_model(cp_aug)


def generate_summary(url):
    results = pipeline(url, model, tokenizer)
    summary = "\n".join(results)
    return summary

def generate_summary_and_video(url):
    summary = generate_summary(url)
    try:
        video_id = url.split("v=")[1].split("&")[0]
        iframe = f'<iframe width="560" height="315" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
        return f"{iframe}\n\n**Summary:**\n{summary}"
    except IndexError:
        return f"**Summary:**\n{summary}\n\nInvalid YouTube URL for video display."

demo = gr.Interface(
    fn=generate_summary_and_video,
    inputs=gr.Textbox(lines=2, placeholder="Enter URL..."),
    outputs=gr.HTML(label="YouTube Video and Summary"),
    title="YouTube Video and Summary Display",
    description="Enter the URL '.'"
)


demo.launch(share=True)