minnehwg's picture
Update app.py
70ebc27 verified
raw
history blame
1.57 kB
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 get_youtube_video(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 iframe
except IndexError:
return "Invalid YouTube URL"
video_interface = gr.Interface(
fn=get_youtube_video,
inputs=gr.Textbox(lines=2, placeholder="Enter YouTube URL..."),
outputs=gr.HTML(label="YouTube Video"),
title="YouTube Video Display",
description="Enter the YouTube URL to display the video."
)
summary_interface = gr.Interface(
fn=generate_summary,
inputs=gr.Textbox(lines=2, placeholder="Enter your URL..."),
outputs=gr.Textbox(label="Generated Text"),
title="Chào mừng đến với hệ thống tóm tắt của Minne >.<",
description="Enter the URL to summarize and click 'Submit' to generate the summary."
)
demo = gr.TabbedInterface([summary_interface, video_interface], ["Summary Generator", "YouTube Video Info"])
demo.launch(share=True)