Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
|
5 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
if
|
22 |
-
|
23 |
-
|
|
|
24 |
else:
|
25 |
-
summary
|
26 |
-
|
|
|
|
|
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()
|