File size: 1,069 Bytes
b9fdd3d
 
 
 
 
 
 
 
9f9be34
 
 
 
 
b9fdd3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f9be34
 
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
import gradio as gr
from transformers import pipeline

# Initialize the model
model = pipeline("summarization", model="luisotorres/bart-finetuned-samsum")

def summarize_text(text):
    try:
        # Dynamically set max_length based on input length
        input_length = len(text.split())
        max_length = min(130, max(30, input_length // 2))
        
        summary = model(text, max_length=max_length, min_length=30)
        return summary[0]["summary_text"]
    except Exception as e:
        return str(e)

# Create Gradio interface
iface = gr.Interface(
    fn=summarize_text,
    inputs=gr.Textbox(label="Input Text", lines=5),
    outputs=gr.Textbox(label="Summary"),
    title="Text Summarization",
    description="Enter your text to generate a summary.",
    examples=[
        ["Sarah: Do you think it's a good idea to invest in Bitcoin?\nEmily: I'm skeptical. The market is very volatile, and you could lose money.\nSarah: True. But there's also a high upside, right?"]
    ]
)

# Launch the interface with public URL enabled
iface.launch(share=True)