File size: 1,609 Bytes
4f78fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1793c7
4f78fd2
 
e1793c7
4f78fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
from parrot import Parrot
import torch
import warnings
warnings.filterwarnings("ignore")
#import nltk #next stage, when executing multiple sentences

import streamlit as st

# ''' 
# uncomment to get reproducable paraphrase generations
# def random_state(seed):
#   torch.manual_seed(seed)
#   if torch.cuda.is_available():
#     torch.cuda.manual_seed_all(seed)

# random_state(1234)
# '''

# #Init models (make sure you init ONLY once if you integrate this to your code)


@st.cache(allow_output_mutation=True)
def load_model():
    # Fetch & load model
    parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
    return parrot
parrot = load_model()

st.title("Let's Rewrite your sentence!")


input_phrase = st.text_input("Input your text here:")
option = st.selectbox('Do you want to preserve some of the original words?',
    ('Yes', 'No'))
if option == 'Yes':
    oc = False
else:
    oc= True


if st.button('Submit Text!'):
    st.header('Input')
    st.write(f" {input_phrase}")
    st.text("--"*30)
    st.header('Output')
    output_phrases = parrot.augment(input_phrase=input_phrase,do_diverse=oc)
    if output_phrases is not None:
        for phrases in output_phrases:
            score = phrases[1]
            sentence = phrases[0]
            if score > 0:
                st.write(sentence)
            else:
                st.write("Sorry! No sentences were found with a good score!")
    else:
        st.write("Sorry! No sentences were found with a good score!")


st.header("Feedback")
st.write("[Kindly consider providing feedback!](https://forms.gle/97st7g2n9NNpqnXw5)")