Spaces:
Running
Running
import gradio as gr | |
from transformers import pipeline | |
# Load the new summarization model | |
summarizer = pipeline("summarization", model="falconsai/text_summarization") | |
def summarize_text(text): | |
max_len = min(0.3 * len(text.split()), 200) # 30% of input length or 200 max | |
min_len = min(0.1 * len(text.split()), 50) # 10% of input length or 50 min | |
summary = summarizer(text, max_length=int(max_len), min_length=int(min_len), do_sample=False) | |
return summary[0]['summary_text'] | |
# Create Gradio Interface | |
iface = gr.Interface( | |
fn=summarize_text, | |
inputs=gr.Textbox(lines=5, placeholder="Enter text to summarize"), | |
outputs="text", | |
title="AI Summarizer", | |
description="Enter a long paragraph, and the AI will summarize it for you.", | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
iface.launch() | |