Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,7 @@ def get_model():
|
|
45 |
|
46 |
model, model2, tokenizer, tokenizer2 = get_model()
|
47 |
|
48 |
-
st.text('''For Prompt Templates: https://huggingface.co/BigSalmon/
|
49 |
|
50 |
temp = st.sidebar.slider("Temperature", 0.7, 1.5)
|
51 |
number_of_outputs = st.sidebar.slider("Number of Outputs", 5, 50)
|
@@ -122,6 +122,16 @@ def run_generate2(text, bad_words):
|
|
122 |
e = e.replace(text, "")
|
123 |
yo.append(e)
|
124 |
return yo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
with st.form(key='my_form'):
|
127 |
text = st.text_area(label='Enter sentence', value=first)
|
@@ -133,6 +143,8 @@ with st.form(key='my_form'):
|
|
133 |
|
134 |
submit_button5 = st.form_submit_button(label='Most Prob')
|
135 |
|
|
|
|
|
136 |
if submit_button:
|
137 |
translated_text = run_generate(text, bad_words)
|
138 |
st.write(translated_text if translated_text else "No translation found")
|
@@ -153,16 +165,19 @@ with st.form(key='my_form'):
|
|
153 |
translated_text = run_generate2(text, bad_words)
|
154 |
st.write(translated_text if translated_text else "No translation found")
|
155 |
if submit_button4:
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
if submit_button5:
|
168 |
-
BestProbs5(text)
|
|
|
|
|
|
|
|
45 |
|
46 |
model, model2, tokenizer, tokenizer2 = get_model()
|
47 |
|
48 |
+
st.text('''For Prompt Templates: https://huggingface.co/BigSalmon/InformalToFormalLincoln82Paraphrase''')
|
49 |
|
50 |
temp = st.sidebar.slider("Temperature", 0.7, 1.5)
|
51 |
number_of_outputs = st.sidebar.slider("Number of Outputs", 5, 50)
|
|
|
122 |
e = e.replace(text, "")
|
123 |
yo.append(e)
|
124 |
return yo
|
125 |
+
|
126 |
+
def prefix_format(sentence):
|
127 |
+
words = sentence.split()
|
128 |
+
if "[MASK]" in sentence:
|
129 |
+
words2 = words.index("[MASK]")
|
130 |
+
#print(words2)
|
131 |
+
output = ("<Prefix> " + ' '.join(words[:words2]) + " <Prefix> " + "<Suffix> " + ' '.join(words[words2+1:]) + " <Suffix>" + " <Middle>")
|
132 |
+
st.write(output)
|
133 |
+
else:
|
134 |
+
st.write("Add [MASK] to sentence")
|
135 |
|
136 |
with st.form(key='my_form'):
|
137 |
text = st.text_area(label='Enter sentence', value=first)
|
|
|
143 |
|
144 |
submit_button5 = st.form_submit_button(label='Most Prob')
|
145 |
|
146 |
+
submit_button6 = st.form_submit_button(label='Turn Sentence with [MASK] into <Prefix> Format')
|
147 |
+
|
148 |
if submit_button:
|
149 |
translated_text = run_generate(text, bad_words)
|
150 |
st.write(translated_text if translated_text else "No translation found")
|
|
|
165 |
translated_text = run_generate2(text, bad_words)
|
166 |
st.write(translated_text if translated_text else "No translation found")
|
167 |
if submit_button4:
|
168 |
+
text2 = str(text)
|
169 |
+
print(text2)
|
170 |
+
text3 = tokenizer2.encode(text2)
|
171 |
+
myinput, past_key_values = torch.tensor([text3]), None
|
172 |
+
myinput = myinput
|
173 |
+
logits, past_key_values = model2(myinput, past_key_values = past_key_values, return_dict=False)
|
174 |
+
logits = logits[0,-1]
|
175 |
+
probabilities = torch.nn.functional.softmax(logits)
|
176 |
+
best_logits, best_indices = logits.topk(logs_outputs)
|
177 |
+
best_words = [tokenizer2.decode([idx.item()]) for idx in best_indices]
|
178 |
+
st.write(best_words)
|
179 |
if submit_button5:
|
180 |
+
BestProbs5(text)
|
181 |
+
if submit_button6:
|
182 |
+
text2 = str(text)
|
183 |
+
prefix_format(text2)
|