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):
    output = text_summary(input)
    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()