Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline, set_seed
|
3 |
|
4 |
-
def
|
5 |
-
# Load the
|
6 |
-
|
7 |
|
8 |
# Set a random seed for reproducibility
|
9 |
set_seed(1)
|
10 |
|
11 |
-
# Generate
|
12 |
-
|
13 |
|
14 |
-
return
|
15 |
|
16 |
def main():
|
17 |
# Set the app title
|
18 |
-
st.title("
|
19 |
-
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
#
|
24 |
-
if
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if __name__ == "__main__":
|
29 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline, set_seed
|
3 |
|
4 |
+
def generate_summary(text):
|
5 |
+
# Load the summarization model
|
6 |
+
summarizer = pipeline("summarization", model="t5-base", max_length=1024, min_length=40)
|
7 |
|
8 |
# Set a random seed for reproducibility
|
9 |
set_seed(1)
|
10 |
|
11 |
+
# Generate summary
|
12 |
+
summary = summarizer(text, num_beams=4, no_repeat_ngram_size=2, length_penalty=2.0, early_stopping=True)[0]['summary_text']
|
13 |
|
14 |
+
return summary
|
15 |
|
16 |
def main():
|
17 |
# Set the app title
|
18 |
+
st.title("Text Summarizer")
|
19 |
+
|
20 |
+
# Create a text box for user input
|
21 |
+
input_text = st.text_area("Enter text to summarize", "")
|
22 |
+
|
23 |
+
# Create a button to generate the summary
|
24 |
+
if st.button("Summarize"):
|
25 |
+
# Generate summary based on user input
|
26 |
+
if input_text:
|
27 |
+
summary = generate_summary(input_text)
|
28 |
+
st.write(summary)
|
29 |
+
else:
|
30 |
+
st.warning("Please enter some text to summarize.")
|
31 |
|
32 |
if __name__ == "__main__":
|
33 |
main()
|