Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
def main():
|
| 5 |
+
st.title("Text Summarization")
|
| 6 |
+
|
| 7 |
+
# Initialize the summarizer pipeline
|
| 8 |
+
summarizer = pipeline(
|
| 9 |
+
task="summarization",
|
| 10 |
+
model="t5-small",
|
| 11 |
+
min_length=20,
|
| 12 |
+
max_length=40,
|
| 13 |
+
truncation=True,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# User input
|
| 17 |
+
input_text = st.text_area("Enter the text you want to summarize:", height=200)
|
| 18 |
+
|
| 19 |
+
# Summarize button
|
| 20 |
+
if st.button("Summarize"):
|
| 21 |
+
if input_text:
|
| 22 |
+
# Generate the summary
|
| 23 |
+
output = summarizer(input_text, max_length=150, min_length=30, do_sample=False)
|
| 24 |
+
summary = output[0]['summary_text']
|
| 25 |
+
|
| 26 |
+
# Display the summary as bullet points
|
| 27 |
+
st.subheader("Summary:")
|
| 28 |
+
bullet_points = summary.split(". ")
|
| 29 |
+
for point in bullet_points:
|
| 30 |
+
st.write(f"- {point.strip()}")
|
| 31 |
+
else:
|
| 32 |
+
st.warning("Please enter text to summarize.")
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
main()
|