Spaces:
Sleeping
Sleeping
Changes made to tf-keras
Browse files- app.py +14 -24
- requirements.txt +4 -3
app.py
CHANGED
@@ -1,30 +1,20 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import BartTokenizer, TFBartForConditionalGeneration
|
3 |
-
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
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(
|
25 |
-
|
26 |
-
|
27 |
-
if
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import BartTokenizer, TFBartForConditionalGeneration
|
3 |
+
model_name = 'facebook/bart-large-cnn'
|
4 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
5 |
+
model = TFBartForConditionalGeneration.from_pretrained(model_name)
|
6 |
|
7 |
+
def summarize(text):
|
8 |
+
inputs = tokenizer.encode(text, return_tensors='tf', max_length=1024, truncation=True)
|
9 |
+
summary_ids = model.generate(inputs, max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
11 |
return summary
|
12 |
|
13 |
+
st.title('Text Summarizer')
|
14 |
+
user_input = st.text_area("Enter text to summarize:", "")
|
15 |
+
if st.button('Summarize'):
|
16 |
+
if user_input:
|
17 |
+
summary = summarize(user_input)
|
18 |
+
st.write(summary)
|
19 |
+
else:
|
20 |
+
st.write("Please enter some text to summarize.")
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
1 |
+
tensorflow==2.12.0
|
2 |
+
transformers==4.29.0
|
3 |
+
tf-keras==2.11.0
|
4 |
+
streamlit==1.22.0
|