File size: 1,203 Bytes
4d483b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
import transformers
from transformers import pipeline, set_seed
import random
import time
import textblob
from textblob import TextBlob

@st.cache
def run_model(input_text):
    set_seed(42)
    model = pipeline("text-generation", model="bert-base-cased", tokenizer="bert-base-cased")
    generated_text = model(input_text, max_length=1024, num_return_sequences=1).generated_text[0]
    return generated_text

def main():
    st.set_page_config(page_title="Paraphraser", page_icon=":guardsman:", layout="wide")
    st.title("Paraphraser")

    input_text = st.text_area("Input Text", "Type your text here")
    options = st.selectbox("Paraphrase Options", ["Correct Grammar", "Remove Special Characters"])

    if options == "Correct Grammar":
        input_text = str(TextBlob(input_text).correct())

    if options == "Remove Special Characters":
        input_text = ''.join(e for e in input_text if e.isalnum() or e.isspace())

    progress_bar = st.progress(0)

    if st.button("Paraphrase"):
        generated_text = run_model(input_text)
        st.write("Generated Text:", generated_text)
        st.write("Paraphrasing completed!")

if __name__ == "__main__":
    main()