Update pages/gpt.py
Browse files- pages/gpt.py +13 -13
pages/gpt.py
CHANGED
|
@@ -5,7 +5,7 @@ import textwrap
|
|
| 5 |
import plotly.express as px
|
| 6 |
|
| 7 |
|
| 8 |
-
st.header(':green[
|
| 9 |
|
| 10 |
tokenizer = GPT2Tokenizer.from_pretrained('sberbank-ai/rugpt3small_based_on_gpt2')
|
| 11 |
model = GPT2LMHeadModel.from_pretrained(
|
|
@@ -13,25 +13,25 @@ model = GPT2LMHeadModel.from_pretrained(
|
|
| 13 |
output_attentions = False,
|
| 14 |
output_hidden_states = False,
|
| 15 |
)
|
| 16 |
-
|
| 17 |
model.load_state_dict(torch.load('models/modelgpt.pt', map_location=torch.device('cpu')))
|
| 18 |
|
| 19 |
|
| 20 |
-
length = st.sidebar.slider('
|
| 21 |
if length > 100:
|
| 22 |
-
st.warning("
|
| 23 |
-
num_samples = st.sidebar.slider('
|
| 24 |
if num_samples > 4:
|
| 25 |
-
st.warning("OH MY ..., I have to work late again!!!", icon="🤖")
|
| 26 |
-
temperature = st.sidebar.slider('
|
| 27 |
-
if
|
| 28 |
-
st.info('What? You want to get some kind of bullshit as a result?', icon="🤖")
|
| 29 |
-
top_k = st.sidebar.slider('
|
| 30 |
-
top_p = st.sidebar.slider('
|
| 31 |
|
| 32 |
|
| 33 |
-
prompt = st.text_input('
|
| 34 |
-
if st.button('
|
| 35 |
|
| 36 |
with torch.inference_mode():
|
| 37 |
prompt = tokenizer.encode(prompt, return_tensors='pt')
|
|
|
|
| 5 |
import plotly.express as px
|
| 6 |
|
| 7 |
|
| 8 |
+
st.header(':green[Text generation by GPT2 model]')
|
| 9 |
|
| 10 |
tokenizer = GPT2Tokenizer.from_pretrained('sberbank-ai/rugpt3small_based_on_gpt2')
|
| 11 |
model = GPT2LMHeadModel.from_pretrained(
|
|
|
|
| 13 |
output_attentions = False,
|
| 14 |
output_hidden_states = False,
|
| 15 |
)
|
| 16 |
+
|
| 17 |
model.load_state_dict(torch.load('models/modelgpt.pt', map_location=torch.device('cpu')))
|
| 18 |
|
| 19 |
|
| 20 |
+
length = st.sidebar.slider('**Generated sequence length:**', 8, 256, 15)
|
| 21 |
if length > 100:
|
| 22 |
+
st.warning("This is very hard for me, please have pity on me. Could you lower the value?", icon="🤖")
|
| 23 |
+
num_samples = st.sidebar.slider('**Number of generations:**', 1, 10, 1)
|
| 24 |
if num_samples > 4:
|
| 25 |
+
st.warning("OH MY ..., I have to work late again!!! Could you lower the value", icon="🤖")
|
| 26 |
+
temperature = st.sidebar.slider('**Temperature:**', 0.1, 10.0, 3.0)
|
| 27 |
+
if temperature > 6.0:
|
| 28 |
+
st.info('What? You want to get some kind of bullshit as a result? Turn down the temperature', icon="🤖")
|
| 29 |
+
top_k = st.sidebar.slider('**Number of most likely generation words:**', 10, 200, 50)
|
| 30 |
+
top_p = st.sidebar.slider('**Minimum total probability of top words:**', 0.4, 1.0, 0.9)
|
| 31 |
|
| 32 |
|
| 33 |
+
prompt = st.text_input('**Enter text 👇:**')
|
| 34 |
+
if st.button('**Generate text**'):
|
| 35 |
|
| 36 |
with torch.inference_mode():
|
| 37 |
prompt = tokenizer.encode(prompt, return_tensors='pt')
|