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,48 +9,24 @@ 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 |
-
# Post-process the summary to include only specific points
|
14 |
-
important_points = extract_important_points(summary)
|
15 |
-
|
16 |
-
return important_points
|
17 |
|
18 |
-
def
|
19 |
-
|
20 |
-
|
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 |
-
#
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
st.title("Text Summarization App")
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
summary
|
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(
|
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.")
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
+
# Load model and tokenizer
|
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 |
+
return summary
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
def save_to_history(input_text, summary_text):
|
15 |
+
with open("history.txt", "a") as file:
|
16 |
+
file.write(f"Input: {input_text}\nSummary: {summary_text}\n\n")
|
|
|
|
|
17 |
|
18 |
+
# Streamlit app
|
19 |
+
st.set_page_config(page_title='Text Summarization App')
|
20 |
+
st.title('Text Summarization App')
|
21 |
|
22 |
+
txt_input = st.text_area('Enter your text', '', height=200)
|
|
|
23 |
|
24 |
+
if st.button('Generate Summary'):
|
25 |
+
if txt_input:
|
26 |
+
with st.spinner('Generating summary...'):
|
27 |
+
summary = generate_summary(txt_input)
|
28 |
+
save_to_history(txt_input, summary)
|
29 |
+
st.subheader('Generated Summary:')
|
30 |
+
st.write(summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
else:
|
32 |
+
st.warning('Please enter some text to summarize.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|