File size: 1,195 Bytes
87b6d29
4dda439
 
c472e77
2a558cf
e7ddb6c
 
ec0f9e2
17dee13
 
e7ddb6c
4dda439
87b6d29
e7ddb6c
a398d23
 
e7ddb6c
 
 
 
a398d23
ec0f9e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import torch
import gradio as gr
from transformers import pipeline

text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)
# text='''Narendra Damodardas Modi[a] (born 17 September 1950) is an Indian politician who has served as the prime minister of India since 2014. Modi was the chief minister of Gujarat from 2001 to 2014 and is the member of parliament (MP) for Varanasi. He is a member of the Bharatiya Janata Party (BJP) and of the Rashtriya Swayamsevak Sangh (RSS), a right-wing Hindutva paramilitary volunteer organisation. He is the longest-serving prime minister outside the Indian National Congress.'''
# print(text_summary(text));

def summary(input_text):
    out = text_summary(input_text)
    return out[0]["summary_text"]  

gr.close_all()
# demo=gr.Interface(fn=summary, inputs="text", outputs="text")
demo = gr.Interface(
    fn=summary,
    inputs=gr.Textbox(label="📝 Input Text", lines=10, placeholder="Paste your text here..."),
    outputs=gr.Textbox(label="📄 Summary", lines=6),
    title="AI Text Summarizer",
    description="Paste any text and get a concise summary powered by DistilBART-CNN.",
)
demo.launch()