sairamn commited on
Commit
b83e654
·
1 Parent(s): 2795772

Changes made to tf-keras

Browse files
Files changed (2) hide show
  1. app.py +14 -24
  2. requirements.txt +4 -3
app.py CHANGED
@@ -1,30 +1,20 @@
1
  import streamlit as st
2
  from transformers import BartTokenizer, TFBartForConditionalGeneration
3
- import tensorflow as tf
 
 
4
 
5
- model_path = 'facebook/bart-large-cnn'
6
- tokenizer_path = model_path
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)
 
 
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
- transformers
2
- tensorflow
3
- streamlit
 
 
1
+ tensorflow==2.12.0
2
+ transformers==4.29.0
3
+ tf-keras==2.11.0
4
+ streamlit==1.22.0