File size: 1,352 Bytes
9bc3866
 
 
97f7894
 
9bc3866
97f7894
 
 
 
 
 
 
 
 
 
 
 
 
9bc3866
97f7894
 
 
 
 
 
 
 
 
 
 
 
 
 
9bc3866
 
97f7894
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
31
32
33
34
35
36
37
38
import gradio as gr
from transformers import pipeline

# Model options available for summarization
model_names = ["Falconsai/text_summarization"]

def summarize_article(article, model_name, max_length, temperature, top_k, top_p):
    """ Summarize the provided article text using the specified model and hyperparameters. """
    summarizer = pipeline("summarization", model=model_name)
    summary = summarizer(
        article,
        max_length=int(round(max_length)),
        min_length=30,
        do_sample=True,
        temperature=temperature,
        top_k=int(round(top_k)),
        top_p=top_p
    )
    return summary[0]['summary_text']

# Gradio interface setup
iface = gr.Interface(
    fn=summarize_article,
    inputs=[
        gr.Textbox(lines=10, placeholder="Enter the article text here..."), 
        gr.Dropdown(choices=model_names, label="Select Model"),
        gr.Slider(minimum=10, maximum=200, step=10, label="Max Length of Summary"),
        gr.Slider(minimum=0.1, maximum=2, step=0.1, label="Temperature for Sampling"),
        gr.Slider(minimum=1, maximum=100, step=1, label="Top-k"),
        gr.Slider(minimum=0.1, maximum=1, step=0.1, label="Top-p")
    ],
    outputs="text",
    title="Text Summarization",
    description="Adjust the parameters below to summarize the article."
)

iface.launch(debug=True, share=True)