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)
summary_html = summary.replace("\n", "
")
try:
video_id = url.split("v=")[1].split("&")[0]
iframe = f''
return f"{iframe}
Những ý chính trong video:
{summary_html}"
except IndexError:
return f"**Summary:**\n{summary}\n\nInvalid YouTube URL for video display."
css = """
.output-html {
font-size: 40px;
}
"""
demo = gr.Interface(
fn=generate_summary_and_video,
inputs=gr.Textbox(lines=2, placeholder="Enter URL..."),
outputs=gr.HTML(label="Results"),
title="Summarizer",
description="Enter the URL to display the YouTube video and summarize the content.",
css=css
)
demo.launch(share=True)