shubhammukherjee commited on
Commit
0167289
·
verified ·
1 Parent(s): 5f8cfa2
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -1,25 +1,38 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Initialize the summarizer pipeline
5
- summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
 
 
 
6
 
7
- def summarize_text(text):
8
- summary = summarizer(text, max_length=150, min_length=50, do_sample=False)
9
- return summary[0]['summary_text']
 
 
10
 
11
- # Streamlit app layout
12
- st.title("Text Summarizer")
13
- st.write("This app uses Hugging Face's transformers to summarize any text you provide.")
14
 
15
- # User input
16
- input_text = st.text_area("Enter Text to Summarize", height=200)
 
17
 
18
  if st.button("Summarize"):
19
- if input_text:
20
- with st.spinner("Summarizing..."):
21
- summary = summarize_text(input_text)
22
- st.subheader("Summary:")
23
- st.write(summary)
 
24
  else:
25
  st.warning("Please enter some text to summarize.")
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ # Available summarization models (you can expand this list)
5
+ available_models = [
6
+ "facebook/t5-small",
7
+ "google/pegasus-xsum",
8
+ "sshleifer/distilbart-cnn-12-6",
9
+ ]
10
 
11
+ @st.cache_resource
12
+ def load_summarizer(model_name):
13
+ """Loads the summarization pipeline for a given model."""
14
+ summarizer = pipeline("summarization", model=model_name)
15
+ return summarizer
16
 
17
+ st.title("Text Summarization App")
 
 
18
 
19
+ text_to_summarize = st.text_area("Enter text to summarize:", height=300)
20
+
21
+ selected_model = st.selectbox("Choose a summarization model:", available_models)
22
 
23
  if st.button("Summarize"):
24
+ if text_to_summarize:
25
+ with st.spinner(f"Summarizing using {selected_model}..."):
26
+ summarizer = load_summarizer(selected_model)
27
+ summary = summarizer(text_to_summarize, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
28
+ st.subheader("Summary:")
29
+ st.write(summary)
30
  else:
31
  st.warning("Please enter some text to summarize.")
32
+
33
+ st.sidebar.header("About")
34
+ st.sidebar.info(
35
+ "This app uses the `transformers` library from Hugging Face "
36
+ "to perform text summarization. You can select from various "
37
+ "pre-trained models."
38
+ )