Spaces:
Running
Running
Zaheer786124
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
#
|
5 |
-
def chunk_text(text, max_length=512):
|
6 |
-
words = text.split()
|
7 |
-
for i in range(0, len(words), max_length):
|
8 |
-
yield " ".join(words[i:i + max_length])
|
9 |
-
|
10 |
-
# Load the Hugging Face model
|
11 |
@st.cache_resource
|
12 |
def load_model():
|
13 |
-
tokenizer =
|
14 |
model = AutoModelForSeq2SeqLM.from_pretrained("Vamsi/T5_Paraphrase_Paws")
|
15 |
return tokenizer, model
|
16 |
|
@@ -28,17 +22,20 @@ if st.button("Paraphrase"):
|
|
28 |
if input_text.strip():
|
29 |
with st.spinner("Paraphrasing... Please wait."):
|
30 |
try:
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
inputs = tokenizer.encode("paraphrase: " + chunk, return_tensors="pt")
|
35 |
-
|
36 |
-
# Generate paraphrased output
|
37 |
-
outputs = model.generate(inputs, num_beams=5, temperature=0.7, early_stopping=True)
|
38 |
-
paraphrased_text += tokenizer.decode(outputs[0], skip_special_tokens=True) + " "
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
st.success("Here is the paraphrased text:")
|
41 |
-
st.write(paraphrased_text
|
42 |
except Exception as e:
|
43 |
st.error(f"An error occurred: {e}")
|
44 |
else:
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import T5Tokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
+
# Load the Hugging Face model with SentencePiece tokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
@st.cache_resource
|
6 |
def load_model():
|
7 |
+
tokenizer = T5Tokenizer.from_pretrained("Vamsi/T5_Paraphrase_Paws")
|
8 |
model = AutoModelForSeq2SeqLM.from_pretrained("Vamsi/T5_Paraphrase_Paws")
|
9 |
return tokenizer, model
|
10 |
|
|
|
22 |
if input_text.strip():
|
23 |
with st.spinner("Paraphrasing... Please wait."):
|
24 |
try:
|
25 |
+
# Prepare input for the model
|
26 |
+
inputs = tokenizer.encode("paraphrase: " + input_text,
|
27 |
+
return_tensors="pt")
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
# Generate paraphrased output
|
30 |
+
outputs = model.generate(
|
31 |
+
inputs,
|
32 |
+
num_beams=5,
|
33 |
+
temperature=0.7,
|
34 |
+
early_stopping=True
|
35 |
+
)
|
36 |
+
paraphrased_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
37 |
st.success("Here is the paraphrased text:")
|
38 |
+
st.write(paraphrased_text)
|
39 |
except Exception as e:
|
40 |
st.error(f"An error occurred: {e}")
|
41 |
else:
|