Spaces:
Sleeping
Sleeping
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) |