Spaces:
Sleeping
Sleeping
import torch | |
import gradio as gr | |
from transformers import pipeline | |
# Use a pipeline as a high-level helper | |
device = 0 if torch.cuda.is_available() else -1 | |
text_summary = pipeline("summarization", model="Falconsai/text_summarization", device=device, torch_dtype=torch.bfloat16) | |
def summary(input): | |
# Calculate the number of tokens based on input length | |
input_length = len(input.split()) | |
max_output_tokens = max(20, input_length // 2) # Ensure output is less than half of the input | |
min_output_tokens = max(10, input_length // 4) # Ensure a meaningful summary | |
# Generate summary with dynamic token limits | |
output = text_summary(input, max_length=max_output_tokens, min_length=min_output_tokens, truncation=True) | |
return output[0]['summary_text'] | |
gr.close_all() | |
# Create the Gradio interface | |
demo = gr.Interface( | |
fn=summary, | |
inputs=[gr.Textbox(label="INPUT THE PASSAGE TO SUMMARIZE", lines=10)], | |
outputs=[gr.Textbox(label="SUMMARIZED TEXT", lines=4)], | |
title="PAVISHINI @ GenAI Project 1: Text Summarizer", | |
description="This application is used to summarize the text" | |
) | |
demo.launch() | |