joermd commited on
Commit
39b8e7a
·
verified ·
1 Parent(s): ccafb67

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (2).py +45 -0
  2. requirements (2).txt +3 -0
app (2).py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import streamlit as st
3
+
4
+ # Load pre-trained BART model for summarization
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
+
7
+ # Summarization function
8
+ def summarize_text(text, max_length=150):
9
+ """
10
+ Summarizes the given text using the pre-trained BART model.
11
+ Args:
12
+ - text (str): The input text to be summarized.
13
+ - max_length (int): Maximum length of the summary.
14
+
15
+ Returns:
16
+ - summary_text (str): The summarized text.
17
+ """
18
+ summary = summarizer(text, max_length=max_length, min_length=50, do_sample=False)
19
+ return summary[0]['summary_text']
20
+
21
+ # Streamlit UI
22
+ def run_streamlit_app():
23
+ """
24
+ This function runs the Streamlit app for text summarization.
25
+ """
26
+ st.title("Text Summarizer")
27
+ st.write("Enter your article and document below to get a summary.")
28
+
29
+ # Text input field for user
30
+ input_text = st.text_area("Enter the Text", height=220)
31
+
32
+ # Button to generate summary
33
+ if st.button("Summarize"):
34
+ if input_text.strip():
35
+ with st.spinner('Summarizing...'):
36
+ summary = summarize_text(input_text)
37
+ st.subheader("Summary:")
38
+ st.write(summary)
39
+ else:
40
+ st.warning("Please enter some text to summarize.")
41
+
42
+ # If this script is being run locally or in an environment where Streamlit is supported,
43
+ # this block will start the Streamlit app
44
+ if __name__ == "__main__":
45
+ run_streamlit_app()
requirements (2).txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers==4.35.0
2
+ torch==2.1.0
3
+ streamlit==1.23.0