Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
| 6 |
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
| 7 |
|
|
@@ -9,24 +9,48 @@ def generate_summary(text):
|
|
| 9 |
inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
|
| 10 |
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
|
| 11 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
st.
|
| 21 |
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
else:
|
| 32 |
-
st.warning(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
+
# Load the tokenizer and model
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
| 6 |
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
| 7 |
|
|
|
|
| 9 |
inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
|
| 10 |
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
|
| 11 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 12 |
+
|
| 13 |
+
# Post-process the summary to include only specific points
|
| 14 |
+
important_points = extract_important_points(summary)
|
| 15 |
+
|
| 16 |
+
return important_points
|
| 17 |
|
| 18 |
+
def extract_important_points(summary):
|
| 19 |
+
# Filter the summary for sentences containing keywords related to change requests or important points
|
| 20 |
+
keywords = ["change", "request", "important", "needs", "must", "critical", "required", "suggested"]
|
| 21 |
+
filtered_lines = [line for line in summary.split('. ') if any(keyword in line.lower() for keyword in keywords)]
|
| 22 |
+
return '. '.join(filtered_lines)
|
| 23 |
|
| 24 |
+
# Initialize session state for input history if it doesn't exist
|
| 25 |
+
if 'input_history' not in st.session_state:
|
| 26 |
+
st.session_state['input_history'] = []
|
| 27 |
|
| 28 |
+
# Streamlit interface
|
| 29 |
+
st.title("Text Summarization App")
|
| 30 |
|
| 31 |
+
# User text input
|
| 32 |
+
user_input = st.text_area("Enter the text you want to summarize", height=200)
|
| 33 |
+
|
| 34 |
+
if st.button("Generate Summary"):
|
| 35 |
+
if user_input:
|
| 36 |
+
with st.spinner("Generating summary..."):
|
| 37 |
+
summary = generate_summary(user_input)
|
| 38 |
+
|
| 39 |
+
# Save the input and summary to the session state history
|
| 40 |
+
st.session_state['input_history'].append({"input": user_input, "summary": summary})
|
| 41 |
+
|
| 42 |
+
st.subheader("Filtered Summary:")
|
| 43 |
+
st.write(summary)
|
| 44 |
else:
|
| 45 |
+
st.warning("Please enter text to summarize.")
|
| 46 |
+
|
| 47 |
+
# Display the history of inputs and summaries
|
| 48 |
+
if st.session_state['input_history']:
|
| 49 |
+
st.subheader("History")
|
| 50 |
+
for i, entry in enumerate(st.session_state['input_history']):
|
| 51 |
+
st.write(f"**Input {i+1}:** {entry['input']}")
|
| 52 |
+
st.write(f"**Summary {i+1}:** {entry['summary']}")
|
| 53 |
+
st.write("---")
|
| 54 |
+
|
| 55 |
+
# Instructions for using the app
|
| 56 |
+
st.write("Enter your text in the box above and click 'Generate Summary' to get a summarized version of your text.")
|