7jimmy commited on
Commit
e2199a7
·
1 Parent(s): c073aa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -1,29 +1,33 @@
1
  import streamlit as st
2
- from transformers import BartTokenizer, BartForSequenceClassification
3
 
4
- def summarize_text(data, max_length):
5
- model_name = "facebook/bart-large-cnn"
6
- model = BartForSequenceClassification.from_pretrained(model_name)
7
- tokenizer = BartTokenizer.from_pretrained(model_name)
8
-
9
- inputs = tokenizer(data, max_length=max_length, return_tensors="pt", truncation=True)
10
- summary_ids = model.generate(inputs["input_ids"])
11
-
12
- summary_text = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
13
- return summary_text
14
 
 
15
  def main():
16
- st.title("Data Summarization")
 
 
 
 
 
 
 
17
 
18
- data = st.text_area("Enter your Data", "")
19
- max_length = st.slider("Summary Length", 20, 1000, 200)
20
 
21
- if st.button("Submit"):
22
- if not data:
23
- st.warning("Please enter some text for summarization.")
 
24
  else:
25
- summary = summarize_text(data, max_length)
26
- st.text_area("Your Summary", summary, height=200)
 
 
27
 
 
28
  if __name__ == "__main__":
29
  main()
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ # Load the summarization model from Hugging Face
5
+ summarizer = pipeline("summarization")
 
 
 
 
 
 
 
 
6
 
7
+ # Streamlit app
8
  def main():
9
+ # Set the title and description of the app
10
+ st.title("Text Summarizer App")
11
+ st.write(
12
+ "Enter a piece of text, select the length of the summary, and get a concise summary!"
13
+ )
14
+
15
+ # Input text box for user input
16
+ input_text = st.text_area("Enter your text here:")
17
 
18
+ # Length selector for summary
19
+ summary_length = st.slider("Select summary length:", min_value=50, max_value=500, value=150, step=50)
20
 
21
+ # Check if the user has entered any text
22
+ if st.button("Generate Summary"):
23
+ if not input_text:
24
+ st.warning("Please enter some text.")
25
  else:
26
+ # Generate summary using the Hugging Face summarization model
27
+ summary = summarizer(input_text, max_length=summary_length, min_length=50, length_penalty=2.0, num_beams=4)
28
+ st.subheader("Summary:")
29
+ st.write(summary[0]["summary_text"])
30
 
31
+ # Run the app
32
  if __name__ == "__main__":
33
  main()