minnehwg commited on
Commit
16e7c81
1 Parent(s): a4a5aff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -9
app.py CHANGED
@@ -1,12 +1,47 @@
 
 
 
1
  import gradio as gr
2
- from util import update
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- with gr.Blocks() as demo:
5
- gr.Markdown("Start typing below and then click **Run** to see the output.")
6
- with gr.Row():
7
- inp = gr.Textbox(placeholder="What is your name?")
8
- out = gr.Textbox()
9
- btn = gr.Button("Run")
10
- btn.click(fn=update, inputs=inp, outputs=out)
11
 
12
- demo.launch()
 
1
+ from util import load_model
2
+ from util import pipeline
3
+
4
  import gradio as gr
5
+ cp_aug = 'minnehwg/finetune-newwiki-summarization-ver-augmented2'
6
+
7
+
8
+ def get_model(cp):
9
+ checkpoint = cp
10
+ tokenizer, model = load_model(checkpoint)
11
+ return tokenizer, model
12
+
13
+ tokenizer, model = get_model(cp_aug)
14
+
15
+
16
+ def generate_summary(url):
17
+ results = pipeline(url, model, tokenizer)
18
+ summary = "\n".join(results)
19
+ return summary
20
+
21
+ def generate_summary_and_video(url):
22
+ summary = generate_summary(url)
23
+ summary_html = summary.replace("\n", "<br>")
24
+ try:
25
+ video_id = url.split("v=")[1].split("&")[0]
26
+ iframe = f'<iframe width="300" height="200" src="https://www.youtube.com/embed/{video_id}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
27
+ return f"{iframe}<br><br>Những ý chính trong video:<br><br>{summary_html}"
28
+ except IndexError:
29
+ return f"**Summary:**\n{summary}\n\nInvalid YouTube URL for video display."
30
+
31
+ css = """
32
+ .output-html {
33
+ font-size: 40px;
34
+ }
35
+ """
36
+
37
+ demo = gr.Interface(
38
+ fn=generate_summary_and_video,
39
+ inputs=gr.Textbox(lines=2, placeholder="Enter URL..."),
40
+ outputs=gr.HTML(label="Results"),
41
+ title="Summarizer",
42
+ description="Enter the URL to display the YouTube video and summarize the content.",
43
+ css=css
44
+ )
45
 
 
 
 
 
 
 
 
46
 
47
+ demo.launch(share=True)