Chanchal15
commited on
Commit
•
4f78fd2
1
Parent(s):
aa8ed88
Initial Commit of the app file
Browse files- app.py +60 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from parrot import Parrot
|
2 |
+
import torch
|
3 |
+
import warnings
|
4 |
+
warnings.filterwarnings("ignore")
|
5 |
+
#import nltk #next stage, when executing multiple sentences
|
6 |
+
|
7 |
+
import streamlit as st
|
8 |
+
|
9 |
+
# '''
|
10 |
+
# uncomment to get reproducable paraphrase generations
|
11 |
+
# def random_state(seed):
|
12 |
+
# torch.manual_seed(seed)
|
13 |
+
# if torch.cuda.is_available():
|
14 |
+
# torch.cuda.manual_seed_all(seed)
|
15 |
+
|
16 |
+
# random_state(1234)
|
17 |
+
# '''
|
18 |
+
|
19 |
+
# #Init models (make sure you init ONLY once if you integrate this to your code)
|
20 |
+
|
21 |
+
|
22 |
+
@st.cache(allow_output_mutation=True)
|
23 |
+
def load_model():
|
24 |
+
# Fetch & load model
|
25 |
+
parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
|
26 |
+
return parrot
|
27 |
+
parrot = load_model()
|
28 |
+
|
29 |
+
st.title("Let's Rewrite your sentence!")
|
30 |
+
|
31 |
+
|
32 |
+
input_phrase = st.text_input("Input your text here:")
|
33 |
+
option = st.selectbox('Do you want to preserve some of the original words?',
|
34 |
+
('Yes', 'No'))
|
35 |
+
if option == 'Yes':
|
36 |
+
oc = False
|
37 |
+
else:
|
38 |
+
oc= True
|
39 |
+
|
40 |
+
|
41 |
+
if st.button('Submit Text!'):
|
42 |
+
st.header(':blue[Input]')
|
43 |
+
st.write(f" {input_phrase}")
|
44 |
+
st.text("--"*30)
|
45 |
+
st.header(':blue[Output]')
|
46 |
+
output_phrases = parrot.augment(input_phrase=input_phrase,do_diverse=oc)
|
47 |
+
if output_phrases is not None:
|
48 |
+
for phrases in output_phrases:
|
49 |
+
score = phrases[1]
|
50 |
+
sentence = phrases[0]
|
51 |
+
if score > 0:
|
52 |
+
st.write(sentence)
|
53 |
+
else:
|
54 |
+
st.write("Sorry! No sentences were found with a good score!")
|
55 |
+
else:
|
56 |
+
st.write("Sorry! No sentences were found with a good score!")
|
57 |
+
|
58 |
+
|
59 |
+
st.header("Feedback")
|
60 |
+
st.write("[Kindly consider providing feedback!](https://forms.gle/97st7g2n9NNpqnXw5)")
|
requirements.txt
ADDED
Binary file (2.57 kB). View file
|
|