File size: 1,196 Bytes
9653e22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
import os
import torch # type: ignore
import transformers # type: ignore
from transformers import pipeline  # type: ignore
import streamlit as st # type: ignore
from dotenv import load_dotenv # type: ignore
import streamlit as st # type: ignore

load_dotenv()

# global variables
model_name = "facebook/bart-large-cnn"
task = "summarization"

# torch cpu
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# huggingface pipeline
summarizer = pipeline(task, model_name, framework='pt', device=device)


# summary generator
def generate_summary(text : str):
    response = summarizer(text, max_length = 100, min_length = 30)
    summary = response[0]['summary_text']
    return summary



# Streamlit App 
st.title('Summary Generator')
st.subheader('Generate summary of any text you want')

text = st.text_area(label = 'Text to analyse', placeholder = 'Write something...', max_chars = 2000)

clicked = st.button('Generate Summary')

progress_text = 'Generating summary...'

if clicked:
    if text=="":
        st.caption('Pls provide some textual input')
    else :
        summary = generate_summary(text)
        st.caption('This is your summary')
        st.write(summary)