Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 11 |
+
# Load the model and tokenizer
|
| 12 |
+
tokenizer, model = load_model()
|
| 13 |
+
|
| 14 |
+
# Streamlit app interface
|
| 15 |
+
st.title("Paraphrasing Tool - AI to Human")
|
| 16 |
+
st.write("Paste your AI-generated text below, and the tool will humanize it:")
|
| 17 |
+
|
| 18 |
+
# Input text box
|
| 19 |
+
input_text = st.text_area("Enter text here (no word limit):")
|
| 20 |
+
|
| 21 |
+
if st.button("Paraphrase"):
|
| 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:
|
| 42 |
+
st.error("Please enter some text to paraphrase.")
|