Spaces:
Running
Running
File size: 1,586 Bytes
14b02b5 | 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 39 40 41 42 43 44 | import torch
import gradio as gr
# Warning: Pipeline type "summarization" is no longer supported in transformers v5.
# You must load the model directly or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline
text_summary = pipeline("summarization", model="Falconsai/text_summarization", dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32)
def summary(input_text):
if not input_text.strip():
return "Please enter document text to summarize."
# Approximate token count using words
input_tokens = len(input_text.split())
# Check if word count is less than 5
if input_tokens < 5:
return "Insufficient text to summarize."
# Proceed with summarization
output = text_summary(input_text, truncation=True)
summary_text = output[0]['summary_text']
# Calculate output tokens (approximate using word count)
output_tokens = len(summary_text.split())
# Debug print statement
print(f"Input tokens: {input_tokens}, Output tokens: {output_tokens}")
return summary_text
gr.close_all()
demo = gr.Interface(fn=summary,
inputs=[gr.Textbox(label="Input text to summarize", lines=8, placeholder="Paste document text here..." )],
outputs=[gr.Textbox(label="Summarized text", lines=4)],
title="AI Text summarization",
description="Powered by FalconsAI T5 Sequence-to-Sequence model.",
flagging_mode="never")
demo.launch()
# demo.launch(share=True) # Creates a public link |