Zain4s commited on
Commit
d419e67
·
verified ·
1 Parent(s): d738ddb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -1,13 +1,22 @@
1
  import streamlit as st
 
 
 
2
 
3
  # Function to clear text
4
  def clear_text():
5
  st.session_state["input_text"] = ""
6
 
 
 
 
 
 
7
  st.title("Text Summarizer")
8
 
9
  input_text = st.text_area("Input", value="", key="input_text", height=300)
10
 
 
11
  col1, col2 = st.columns([1, 1])
12
  with col1:
13
  if st.button("Clear", on_click=clear_text):
@@ -15,5 +24,8 @@ with col1:
15
 
16
  with col2:
17
  if st.button("Submit"):
18
- # The functionality for submitting and summarizing will be added later
19
- st.text_area("Summary", value="Test", height=300)
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ summarizer = pipeline("summarization", model="bart_base_samsum")
5
 
6
  # Function to clear text
7
  def clear_text():
8
  st.session_state["input_text"] = ""
9
 
10
+ # Function to summarize text
11
+ def summarize_text(text):
12
+ summary = summarizer(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
13
+ return summary
14
+
15
  st.title("Text Summarizer")
16
 
17
  input_text = st.text_area("Input", value="", key="input_text", height=300)
18
 
19
+ # Clear & Submit bittons
20
  col1, col2 = st.columns([1, 1])
21
  with col1:
22
  if st.button("Clear", on_click=clear_text):
 
24
 
25
  with col2:
26
  if st.button("Submit"):
27
+ if input_text.strip():
28
+ summary = summarize_text(input_text)
29
+ st.text_area("Summary", value=summary, height=300)
30
+ else:
31
+ st.warning("Please enter some text to summarize.")