Spaces:
Runtime error
Runtime error
# -*- coding: utf-8 -*- | |
from transformers import pipeline | |
import gradio as gr | |
from gradio.components import Textbox | |
import random | |
import json | |
examples = [] | |
with open('sample_data.jsonl', 'r', encoding='utf-8') as file: | |
for line in file: | |
data_dict = json.loads(line) | |
examples.append(data_dict["text"]) | |
def random_sample(): | |
random_number = random.randint(0, len(examples) - 1) | |
return examples[random_number] | |
summarization = pipeline("summarization", model=f"xjlulu/ntu_adl_summarization_mt5_s", framework="pt") | |
def generate_answer(context): | |
result = summarization(context) | |
return result[0]['summary_text'] | |
description=""" | |
# Text Summarization | |
Enter a text paragraph to generate a title. | |
""" | |
with gr.Blocks(theme=gr.themes.Soft(), title="Text Summarization") as demo: | |
gr.Markdown(description) | |
S_output = Textbox(lines=3, label="title") | |
with gr.Row(): | |
random_button = gr.Button("Random") | |
generate_button = gr.Button("Generate") | |
C_input = gr.Textbox(lines=6, label="Context paragraph", placeholder="Please enter text") | |
random_button.click(random_sample, inputs=None, outputs=C_input) | |
generate_button.click(generate_answer, inputs=C_input, outputs=S_output) | |
demo.launch() |