H
File size: 1,090 Bytes
c740fb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# import necessary libraries
import streamlit as st
from transformers import BartForConditionalGeneration, BartTokenizer

# Load BART model and tokenizer
model_name = "facebook/bart-large-cnn"
model = BartForConditionalGeneration.from_pretrained(model_name)
tokenizer = BartTokenizer.from_pretrained(model_name)

# Streamlit app
st.title("ANavya Text Summarizer")

# Create a text input box
text_input = st.text_area("Enter Text Here:")

# Function to summarize text
def summarize_text(text):
    input_ids = tokenizer.encode(text, return_tensors="pt", max_length=1024, truncation=True)
    summary_ids = model.generate(input_ids, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    return summary

# Create a submit button
if st.button("Submit", key="ANavya"):
    if text_input:
        st.subheader("Summary:")
        summary = summarize_text(text_input)
        st.write(summary)

# Display a footer or additional information
st.sidebar.markdown("Created by [Team Anavya]")