sharath6900 commited on
Commit
8844977
·
verified ·
1 Parent(s): 526d29a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -17
app.py CHANGED
@@ -1,7 +1,7 @@
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,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
- 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.')
 
 
 
 
 
 
 
 
 
 
 
 
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.")