Sharvesh
commited on
Commit
·
c740fb0
1
Parent(s):
a8a1625
Upload check.py
Browse files
check.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import necessary libraries
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
| 4 |
+
|
| 5 |
+
# Load BART model and tokenizer
|
| 6 |
+
model_name = "facebook/bart-large-cnn"
|
| 7 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
| 8 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Streamlit app
|
| 11 |
+
st.title("ANavya Text Summarizer")
|
| 12 |
+
|
| 13 |
+
# Create a text input box
|
| 14 |
+
text_input = st.text_area("Enter Text Here:")
|
| 15 |
+
|
| 16 |
+
# Function to summarize text
|
| 17 |
+
def summarize_text(text):
|
| 18 |
+
input_ids = tokenizer.encode(text, return_tensors="pt", max_length=1024, truncation=True)
|
| 19 |
+
summary_ids = model.generate(input_ids, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
|
| 20 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 21 |
+
return summary
|
| 22 |
+
|
| 23 |
+
# Create a submit button
|
| 24 |
+
if st.button("Submit", key="ANavya"):
|
| 25 |
+
if text_input:
|
| 26 |
+
st.subheader("Summary:")
|
| 27 |
+
summary = summarize_text(text_input)
|
| 28 |
+
st.write(summary)
|
| 29 |
+
|
| 30 |
+
# Display a footer or additional information
|
| 31 |
+
st.sidebar.markdown("Created by [Team Anavya]")
|
| 32 |
+
|