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