Spaces:
Runtime error
Runtime error
Simon Salmon
commited on
Commit
·
e0e7abc
1
Parent(s):
210b713
Update app.py
Browse files
app.py
CHANGED
@@ -13,23 +13,26 @@ st.title('KoGPT2 Demo')
|
|
13 |
|
14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
with st.form(key='my_form'):
|
20 |
-
|
21 |
submit_button = st.form_submit_button(label='Submit')
|
22 |
|
23 |
if submit_button:
|
24 |
with torch.no_grad():
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
13 |
|
14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained("BigSalmon/SimplifyText")
|
18 |
+
model = AutoModelWithLMHead.from_pretrained("BigSalmon/SimplifyText")
|
19 |
|
20 |
with st.form(key='my_form'):
|
21 |
+
prompt = st.text_input(label='Enter sentence')
|
22 |
submit_button = st.form_submit_button(label='Submit')
|
23 |
|
24 |
if submit_button:
|
25 |
with torch.no_grad():
|
26 |
+
text = tokenizer.encode(prompt)
|
27 |
+
myinput, past_key_values = torch.tensor([text]), None
|
28 |
+
myinput = myinput
|
29 |
+
myinput= myinput.to(device)
|
30 |
+
logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
|
31 |
+
logits = logits[0,-1]
|
32 |
+
probabilities = torch.nn.functional.softmax(logits)
|
33 |
+
best_logits, best_indices = logits.topk(4)
|
34 |
+
best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
|
35 |
+
text.append(best_indices[0].item())
|
36 |
+
best_probabilities = probabilities[best_indices].tolist()
|
37 |
+
words = []
|
38 |
+
st.write(best_words)
|