Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,21 +5,14 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
6 |
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
7 |
|
8 |
-
def generate_summary(text):
|
9 |
-
|
|
|
|
|
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 |
-
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:
|
@@ -28,29 +21,31 @@ if 'input_history' not in st.session_state:
|
|
28 |
# Streamlit interface
|
29 |
st.title("Text Summarization App")
|
30 |
|
31 |
-
# User text
|
32 |
-
|
|
|
33 |
|
34 |
if st.button("Generate Summary"):
|
35 |
-
if
|
36 |
with st.spinner("Generating summary..."):
|
37 |
-
summary = generate_summary(
|
38 |
|
39 |
# Save the input and summary to the session state history
|
40 |
-
st.session_state['input_history'].append({"
|
41 |
|
42 |
-
st.subheader("
|
43 |
st.write(summary)
|
44 |
else:
|
45 |
-
st.warning("Please enter text
|
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['
|
|
|
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
|
|
|
5 |
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
6 |
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
|
7 |
|
8 |
+
def generate_summary(text, prompt):
|
9 |
+
# Combine text and prompt into one input
|
10 |
+
combined_input = f"{prompt}: {text}"
|
11 |
+
inputs = tokenizer([combined_input], max_length=1024, return_tensors='pt', truncation=True)
|
12 |
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
|
13 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
14 |
|
15 |
+
return summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Initialize session state for input history if it doesn't exist
|
18 |
if 'input_history' not in st.session_state:
|
|
|
21 |
# Streamlit interface
|
22 |
st.title("Text Summarization App")
|
23 |
|
24 |
+
# User text inputs
|
25 |
+
bulk_text = st.text_area("Enter the bulk text you want to summarize", height=200)
|
26 |
+
prompt = st.text_input("Enter the prompt for the summary", "What are the key points?")
|
27 |
|
28 |
if st.button("Generate Summary"):
|
29 |
+
if bulk_text and prompt:
|
30 |
with st.spinner("Generating summary..."):
|
31 |
+
summary = generate_summary(bulk_text, prompt)
|
32 |
|
33 |
# Save the input and summary to the session state history
|
34 |
+
st.session_state['input_history'].append({"text": bulk_text, "prompt": prompt, "summary": summary})
|
35 |
|
36 |
+
st.subheader("Generated Summary:")
|
37 |
st.write(summary)
|
38 |
else:
|
39 |
+
st.warning("Please enter both the bulk text and the prompt.")
|
40 |
|
41 |
# Display the history of inputs and summaries
|
42 |
if st.session_state['input_history']:
|
43 |
st.subheader("History")
|
44 |
for i, entry in enumerate(st.session_state['input_history']):
|
45 |
+
st.write(f"**Input {i+1} (Text):** {entry['text']}")
|
46 |
+
st.write(f"**Prompt {i+1}:** {entry['prompt']}")
|
47 |
st.write(f"**Summary {i+1}:** {entry['summary']}")
|
48 |
st.write("---")
|
49 |
|
50 |
# Instructions for using the app
|
51 |
+
st.write("Enter your bulk text and a prompt for summarization, then click 'Generate Summary' to get a summarized version based on your prompt.")
|