Update app.py
Browse files
app.py
CHANGED
@@ -189,6 +189,24 @@ def BestProbs5(prompt):
|
|
189 |
l = run_generate(g, "hey")
|
190 |
st.write(l)
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
def run_generate(text, bad_words):
|
193 |
yo = []
|
194 |
input_ids = tokenizer.encode(text, return_tensors='pt')
|
@@ -222,6 +240,7 @@ with st.form(key='my_form'):
|
|
222 |
submit_button2 = st.form_submit_button(label='Fast Forward')
|
223 |
submit_button3 = st.form_submit_button(label='Fast Forward 2.0')
|
224 |
submit_button4 = st.form_submit_button(label='Get Top')
|
|
|
225 |
|
226 |
if submit_button:
|
227 |
with torch.no_grad():
|
@@ -250,4 +269,7 @@ with st.form(key='my_form'):
|
|
250 |
st.write("___")
|
251 |
st.write(BestProbs)
|
252 |
if submit_button4:
|
253 |
-
BestProbs5(prompt)
|
|
|
|
|
|
|
|
189 |
l = run_generate(g, "hey")
|
190 |
st.write(l)
|
191 |
|
192 |
+
def syn(prompt, word):
|
193 |
+
prompt = prompt.strip()
|
194 |
+
prompt = prompt.split(word)[0]
|
195 |
+
prompt = "Translated into the Style of Abraham Lincoln: " + prompt + "( " + word + " /"
|
196 |
+
#prompt = prompt.replace("/ ", "/")
|
197 |
+
print(prompt)
|
198 |
+
text = tokenizer.encode(prompt)
|
199 |
+
myinput, past_key_values = torch.tensor([text]), None
|
200 |
+
myinput = myinput
|
201 |
+
logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
|
202 |
+
logits = logits[0,-1]
|
203 |
+
probabilities = torch.nn.functional.softmax(logits)
|
204 |
+
best_logits, best_indices = logits.topk(100)
|
205 |
+
best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
|
206 |
+
for i in best_words[0:100]:
|
207 |
+
print(prompt)
|
208 |
+
st.write(i)
|
209 |
+
|
210 |
def run_generate(text, bad_words):
|
211 |
yo = []
|
212 |
input_ids = tokenizer.encode(text, return_tensors='pt')
|
|
|
240 |
submit_button2 = st.form_submit_button(label='Fast Forward')
|
241 |
submit_button3 = st.form_submit_button(label='Fast Forward 2.0')
|
242 |
submit_button4 = st.form_submit_button(label='Get Top')
|
243 |
+
submit_button5 = st.form_submit_button(label='Synonyms')
|
244 |
|
245 |
if submit_button:
|
246 |
with torch.no_grad():
|
|
|
269 |
st.write("___")
|
270 |
st.write(BestProbs)
|
271 |
if submit_button4:
|
272 |
+
BestProbs5(prompt)
|
273 |
+
if submit_button5:
|
274 |
+
bad_words = st.text_input("Word Or Phrase You Want Syn For", "yielded to")
|
275 |
+
syn(prompt, bad_words)
|