Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,12 @@
|
|
1 |
-
|
2 |
-
from util import load_model
|
3 |
-
from util import pipeline
|
4 |
-
|
5 |
import gradio as gr
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
def get_model(cp):
|
10 |
-
checkpoint = cp
|
11 |
-
tokenizer, model = load_model(checkpoint)
|
12 |
-
return tokenizer, model
|
13 |
-
|
14 |
-
tokenizer, model = get_model(cp_aug)
|
15 |
-
|
16 |
-
|
17 |
-
def generate_summary(url):
|
18 |
-
results = pipeline(url, model, tokenizer)
|
19 |
-
summary = "\n".join(results)
|
20 |
-
return summary
|
21 |
-
|
22 |
-
def generate_summary_and_video(url):
|
23 |
-
summary = generate_summary(url)
|
24 |
-
summary_html = summary.replace("\n", "<br>")
|
25 |
-
try:
|
26 |
-
video_id = url.split("v=")[1].split("&")[0]
|
27 |
-
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>'
|
28 |
-
return f"{iframe}<br><br>Những ý chính trong video:<br><br>{summary_html}"
|
29 |
-
except IndexError:
|
30 |
-
return f"**Summary:**\n{summary}\n\nInvalid YouTube URL for video display."
|
31 |
-
|
32 |
-
css = """
|
33 |
-
.output-html {
|
34 |
-
font-size: 40px;
|
35 |
-
}
|
36 |
-
"""
|
37 |
-
|
38 |
-
demo = gr.Interface(
|
39 |
-
fn=generate_summary_and_video,
|
40 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter URL..."),
|
41 |
-
outputs=gr.HTML(label="Results"),
|
42 |
-
title="Summarizer",
|
43 |
-
description="Enter the URL to display the YouTube video and summarize the content.",
|
44 |
-
css=css
|
45 |
-
)
|
46 |
-
|
47 |
-
|
48 |
-
demo.launch(share=True)
|
49 |
-
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
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()
|