Spaces:
Sleeping
Sleeping
Initial commit
Browse files- app.py +30 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import BartTokenizer, TFBartForConditionalGeneration
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
model_path = 'facebook/bart-large-cnn'
|
6 |
+
tokenizer_path = 'facebook/bart-large-cnn'
|
7 |
+
|
8 |
+
tokenizer = BartTokenizer.from_pretrained(tokenizer_path)
|
9 |
+
model = TFBartForConditionalGeneration.from_pretrained(model_path)
|
10 |
+
|
11 |
+
def summarize_text(text):
|
12 |
+
inputs = tokenizer.encode('summarize: ' + text, return_tensors='tf', max_length=1024, truncation=True)
|
13 |
+
summary_ids = model.generate(
|
14 |
+
inputs,
|
15 |
+
max_length=150,
|
16 |
+
min_length=40,
|
17 |
+
length_penalty=2.0,
|
18 |
+
num_beams=4,
|
19 |
+
early_stopping=True
|
20 |
+
)
|
21 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
22 |
+
return summary
|
23 |
+
|
24 |
+
st.title("Text Summarization")
|
25 |
+
text = st.text_area("Enter text to summarize", height=200)
|
26 |
+
|
27 |
+
if st.button("Summarize"):
|
28 |
+
summary = summarize_text(text)
|
29 |
+
st.write("Summary:")
|
30 |
+
st.write(summary)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
tensorflow
|
3 |
+
streamlit
|