zoya23 commited on
Commit
fec6ac6
·
verified ·
1 Parent(s): 4a7c728

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -1,22 +1,38 @@
1
  import streamlit as st
2
  import transformers
 
3
 
4
- from transformers import pipeline
 
 
5
 
6
- st.title("Text Summarization App")
 
7
 
8
- model_choice = st.selectbox("Choose a Model", ["BART", "T5", "PEGASUS"])
 
 
 
 
 
9
 
10
- text_input = st.text_area("Enter text to summarize:")
 
 
 
 
 
11
 
 
 
 
 
12
  if st.button("Summarize"):
13
- if model_choice == "BART":
14
- summarizer = pipeline("summarization", model="BART")
15
- elif model_choice == "T5":
16
- summarizer = pipeline("summarization", model="T5")
17
  else:
18
- summarizer = pipeline("summarization", model="PEGASUS")
19
-
20
- summary = summarizer(text_input, max_length=150, min_length=40, do_sample=False)
21
- st.subheader("Summary:")
22
- st.write(summary[0]['summary_text'])
 
1
  import streamlit as st
2
  import transformers
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
4
 
5
+ # Title
6
+ st.markdown("<h1 style='text-align: center; color: black;'>Text Summarization App</h1>", unsafe_allow_html=True)
7
+ st.markdown("---")
8
 
9
+ # Model Selection
10
+ model_choice = st.selectbox("Select a Summarization Model", ["BART", "T5", "PEGASUS"])
11
 
12
+ # Load model and tokenizer
13
+ @st.cache_resource
14
+ def load_model(model_name):
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
17
+ return pipeline("summarization", model=model, tokenizer=tokenizer)
18
 
19
+ # Map choices to model names or paths
20
+ model_map = {
21
+ "BART": "facebook/bart-large-cnn",
22
+ "T5": "t5-small",
23
+ "PEGASUS": "google/pegasus-cnn_dailymail"
24
+ }
25
 
26
+ # Text Input
27
+ text_input = st.text_area("Enter the text you want to summarize:", height=300)
28
+
29
+ # Button to generate summary
30
  if st.button("Summarize"):
31
+ if not text_input.strip():
32
+ st.warning("Please enter some text!")
 
 
33
  else:
34
+ summarizer = load_model(model_map[model_choice])
35
+ summary = summarizer(text_input, max_length=150, min_length=40, do_sample=False)
36
+
37
+ st.markdown("### Summary:")
38
+ st.success(summary[0]['summary_text'])