Spaces:
Runtime error
Runtime error
Danil
commited on
Commit
Β·
d928ac3
1
Parent(s):
c970b51
Upload streamlit.py
Browse files- streamlit.py +45 -0
streamlit.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
+
|
4 |
+
@st.cache(allow_output_mutation=True)
|
5 |
+
def load_model():
|
6 |
+
'''
|
7 |
+
Loads the model and tokenizer from the local directory.
|
8 |
+
:return: A list containing the model and the tokenizer.
|
9 |
+
'''
|
10 |
+
model_name = 'WIP'
|
11 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
12 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
13 |
+
return [model, tokenizer]
|
14 |
+
|
15 |
+
st.set_page_config(
|
16 |
+
page_title="BulgakovLM Example",
|
17 |
+
page_icon="π¨βπ»",
|
18 |
+
)
|
19 |
+
|
20 |
+
st.markdown("# π¨βπ» BulgakovLM Example")
|
21 |
+
|
22 |
+
txt = st.text_area('Write code here', '''ΠΠ΄Π½Π°ΠΆΠ΄Ρ ΡΡΡΠΎΠΌ''', height=400)
|
23 |
+
|
24 |
+
gen = st.button('Generate')
|
25 |
+
|
26 |
+
c = st.code('')
|
27 |
+
|
28 |
+
max_length = st.slider('max_length', 1, 1024, 128)
|
29 |
+
top_k = st.slider('top_k', 0, 100, 50)
|
30 |
+
top_p = st.slider('top_p', 0.0, 1.0, 0.9)
|
31 |
+
temperature = st.slider('temperature', 0.0, 1.0, 1.0)
|
32 |
+
num_beams = st.slider('num_beams', 1, 100, 5)
|
33 |
+
repetition_penalty = st.slider('repetition_penalty', 1.0, 10.0, 1.0)
|
34 |
+
|
35 |
+
|
36 |
+
if gen:
|
37 |
+
c.code('Generating...')
|
38 |
+
m = load_model()
|
39 |
+
|
40 |
+
inpt = m[1].encode(txt, return_tensors="pt")
|
41 |
+
out = m[0].generate(inpt, max_length=max_length, top_p=top_p, top_k=top_k, temperature=temperature, num_beams=num_beams, repetition_penalty=repetition_penalty)
|
42 |
+
res = m[1].decode(out[0])
|
43 |
+
|
44 |
+
print('ok')
|
45 |
+
c.code(res)
|