Spaces:
Runtime error
Runtime error
prouditalian
commited on
Commit
·
8b05fe9
1
Parent(s):
97858e6
Create app_test.py
Browse files- app_test.py +20 -0
app_test.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
tokenizer = GPT2Tokenizer.from_pretrained("sberbank-ai/mGPT")
|
5 |
+
model = GPT2LMHeadModel.from_pretrained("sberbank-ai/mGPT")
|
6 |
+
|
7 |
+
text = "Александр Сергеевич Пушкин родился в "
|
8 |
+
input_ids = tokenizer.encode(text, return_tensors="pt").cuda(device)
|
9 |
+
out = model.generate(
|
10 |
+
input_ids,
|
11 |
+
min_length=100,
|
12 |
+
max_length=100,
|
13 |
+
eos_token_id=5,
|
14 |
+
pad_token=1,
|
15 |
+
top_k=10,
|
16 |
+
top_p=0.0,
|
17 |
+
no_repeat_ngram_size=5
|
18 |
+
)
|
19 |
+
generated_text = list(map(tokenizer.decode, out))[0]
|
20 |
+
st.write(generated_text)
|