Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,18 @@ 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 |
# Streamlit interface
|
| 15 |
st.title("Text Summarization App")
|
|
@@ -21,7 +32,7 @@ if st.button("Generate Summary"):
|
|
| 21 |
if user_input:
|
| 22 |
with st.spinner("Generating summary..."):
|
| 23 |
summary = generate_summary(user_input)
|
| 24 |
-
st.subheader("Summary:")
|
| 25 |
st.write(summary)
|
| 26 |
else:
|
| 27 |
st.warning("Please enter text to summarize.")
|
|
|
|
| 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 |
+
# This is a very basic example of how you might filter for key phrases
|
| 20 |
+
# You can refine this with more sophisticated NLP techniques
|
| 21 |
+
keywords = ["change", "request", "important", "needs", "must", "critical", "required", "suggested"]
|
| 22 |
+
filtered_lines = [line for line in summary.split('. ') if any(keyword in line.lower() for keyword in keywords)]
|
| 23 |
+
return '. '.join(filtered_lines)
|
| 24 |
|
| 25 |
# Streamlit interface
|
| 26 |
st.title("Text Summarization App")
|
|
|
|
| 32 |
if user_input:
|
| 33 |
with st.spinner("Generating summary..."):
|
| 34 |
summary = generate_summary(user_input)
|
| 35 |
+
st.subheader("Filtered Summary:")
|
| 36 |
st.write(summary)
|
| 37 |
else:
|
| 38 |
st.warning("Please enter text to summarize.")
|