Spaces:
Sleeping
Sleeping
File size: 2,377 Bytes
c71b2e8 8fff906 b17a76b c71b2e8 8fff906 b17a76b 8fff906 35d8013 7f33eef 35d8013 8fff906 7f33eef c71b2e8 7f33eef 35d8013 c71b2e8 7f33eef c71b2e8 |
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 48 49 50 51 52 53 54 55 56 57 |
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
def generate_summary(text):
inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
# Post-process the summary to include only specific points
important_points = extract_important_points(summary)
return important_points
def extract_important_points(summary):
# Filter the summary for sentences containing keywords related to change requests or important points
keywords = ["change", "request", "important", "needs", "must", "critical", "required", "suggested"]
filtered_lines = [line for line in summary.split('. ') if any(keyword in line.lower() for keyword in keywords)]
return '. '.join(filtered_lines)
# Initialize session state for input history if it doesn't exist
if 'input_history' not in st.session_state:
st.session_state['input_history'] = []
# Streamlit interface
st.title("Text Summarization App")
# User text input
user_input = st.text_area("Enter the text you want to summarize", height=200)
if st.button("Generate Summary"):
if user_input:
with st.spinner("Generating summary..."):
summary = generate_summary(user_input)
# Save the input and summary to the session state history
st.session_state['input_history'].append({"input": user_input, "summary": summary})
st.subheader("Filtered Summary:")
st.write(summary)
else:
st.warning("Please enter text to summarize.")
# Display the history of inputs and summaries
if st.session_state['input_history']:
st.subheader("History")
for i, entry in enumerate(st.session_state['input_history']):
st.write(f"**Input {i+1}:** {entry['input']}")
st.write(f"**Summary {i+1}:** {entry['summary']}")
st.write("---")
# Instructions for using the app
st.write("Enter your text in the box above and click 'Generate Summary' to get a summarized version of your text.")
|