Spaces:
Runtime error
Runtime error
File size: 1,684 Bytes
b5676ef 4cbafd6 e79ccab 1d1ada0 b5676ef 4cbafd6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
from transformers import pipeline
def summarize_article(article, model_name, max_length, temperature, top_k, top_p):
summarizer = pipeline("summarization", model=model_name)
top_k = int(round(top_k))
max_length = int(round(max_length))
summary = summarizer(article, max_length=max_length, min_length=30, do_sample=True, temperature=temperature, top_k=top_k, top_p=top_p)
return summary[0]['summary_text']
iface = gr.Interface(
fn=summarize_article,
inputs=[
gr.Textbox(
label="Article",
lines=10,
value="William Shakespeare would have lived with his family in their house on Henley Street until he turned eighteen. When he was eighteen, Shakespeare married Anne Hathaway, who was twenty-six. It was a rushed marriage because Anne was already pregnant at the time of the ceremony. Together they had three children. Their first daughter, Susanna, was born six months after the wedding and was later followed by twins Hamnet and Judith. Hamnet died when he was just 11 years old."
),
gr.Dropdown(["Falconsai/text_summarization", "Other Models..."], label="Select Model"),
gr.Slider(minimum=10, maximum=200, value=100, label="Max-Length"),
gr.Slider(minimum=0.1, maximum=2, value=0.7, label="Temperature"),
gr.Slider(minimum=1, maximum=100, value=50, label="Top-k"),
gr.Slider(minimum=0.1, maximum=1, value=0.9, label="Top-p")
],
outputs="text",
title="Text Summarization with Hyperparameters",
description="Enter an article, select a model, and adjust hyperparameters for summarization."
)
iface.launch(debug=True, share=True) |