File size: 1,585 Bytes
4d483b8
 
 
 
 
 
 
373e47b
 
 
4d483b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373e47b
 
 
 
 
 
 
 
4d483b8
 
0347ebc
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
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import transformers
from transformers import pipeline, set_seed
import random
import time
import textblob
from textblob import TextBlob
from flask import Flask, request

app = Flask(__name__)

@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!")
        st.write("")
        st.write("Click the button below to copy the generated text to your clipboard:")
        st.button("Copy to Clipboard", script="document.execCommand('copy');", key="copy")

@app.route("/", methods=["GET", "POST"])
def index():
    main()
    return st.get_html_str()

if __name__ == "__main__":
    app.run() #host="0.0.0.0",port=7860)