karthi311 commited on
Commit
9bb33c5
·
verified ·
1 Parent(s): 90c041b

Create app1.py

Browse files
Files changed (1) hide show
  1. app1.py +29 -0
app1.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Initialize summarization pipeline
5
+ summarizer = pipeline("summarization")
6
+ # Streamlit UI setup
7
+ st.title("📝 Text Summarization App")
8
+
9
+ # User input box (allows large input text)
10
+ user_input = st.text_area("Enter text to summarize:", "", height=300)
11
+
12
+ # Button to trigger summarization
13
+ if st.button("Summarize"):
14
+ if user_input.strip(): # Ensure there's input before summarizing
15
+ try:
16
+ # Adjust max_length based on input size (e.g., for small inputs, use a lower max_length)
17
+ max_length = 50 if len(user_input.split()) <= 50 else 150
18
+
19
+ # Generate summary using the model
20
+ summarized_text = summarizer(user_input, max_length=max_length, min_length=5, length_penalty=2.0, num_beams=4, early_stopping=True)[0]['summary_text']
21
+
22
+ # Display the generated summary
23
+ st.subheader("Summarized Text:")
24
+ st.write(summarized_text)
25
+
26
+ except Exception as e:
27
+ st.error(f"An error occurred while summarizing: {e}")
28
+ else:
29
+ st.warning("Please enter some text to summarize.")