Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import streamlit as st
|
|
5 |
import re
|
6 |
|
7 |
from PIL import Image
|
8 |
-
from huggingface_hub import hf_hub_download
|
9 |
|
10 |
|
11 |
@st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None, re.Pattern: lambda _: None}, allow_output_mutation=True, suppress_st_warning=True)
|
@@ -21,7 +20,6 @@ def get_model(model_name, model_path):
|
|
21 |
return model, tokenizer
|
22 |
|
23 |
|
24 |
-
#@st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None, re.Pattern: lambda _: None}, allow_output_mutation=True, suppress_st_warning=True)
|
25 |
def predict(text, model, tokenizer, n_beams=5, temperature=2.5, top_p=0.8, length_of_generated=300):
|
26 |
text += '\n'
|
27 |
input_ids = tokenizer.encode(text, return_tensors="pt")
|
@@ -45,34 +43,27 @@ large_model, large_tokenizer = get_model('sberbank-ai/rugpt3large_based_on_gpt2'
|
|
45 |
# st.title("NeuroKorzh")
|
46 |
|
47 |
image = Image.open('korzh.jpg')
|
48 |
-
st.image(image, caption='
|
49 |
|
50 |
-
option = st.selectbox('
|
|
|
51 |
|
52 |
st.markdown("\n")
|
53 |
|
54 |
-
text = st.text_area(label='
|
55 |
-
button = st.button('
|
56 |
|
57 |
if button:
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
#for line in lines:
|
70 |
-
# st.write(line)
|
71 |
-
|
72 |
-
#lines = result.replace('\n', '\n\n')
|
73 |
-
#st.write(lines)
|
74 |
-
|
75 |
-
st.text_area(label='', value=result, height=1200)
|
76 |
-
|
77 |
-
#except Exception:
|
78 |
-
# st.error("Ooooops, something went wrong. Try again please and report to me, tg: @vladyur")
|
|
|
5 |
import re
|
6 |
|
7 |
from PIL import Image
|
|
|
8 |
|
9 |
|
10 |
@st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None, re.Pattern: lambda _: None}, allow_output_mutation=True, suppress_st_warning=True)
|
|
|
20 |
return model, tokenizer
|
21 |
|
22 |
|
|
|
23 |
def predict(text, model, tokenizer, n_beams=5, temperature=2.5, top_p=0.8, length_of_generated=300):
|
24 |
text += '\n'
|
25 |
input_ids = tokenizer.encode(text, return_tensors="pt")
|
|
|
43 |
# st.title("NeuroKorzh")
|
44 |
|
45 |
image = Image.open('korzh.jpg')
|
46 |
+
st.image(image, caption='НейроКорж')
|
47 |
|
48 |
+
option = st.selectbox('Выберите своего Коржа', ('Быстрый', 'Глубокий'))
|
49 |
+
craziness = st.slider(label='Абсурдность', min_value=0.5, max_value=4, value=2.5, step=0.1)
|
50 |
|
51 |
st.markdown("\n")
|
52 |
|
53 |
+
text = st.text_area(label='Напишите начало песни', value='Что делать, Макс?', height=100)
|
54 |
+
button = st.button('Старт')
|
55 |
|
56 |
if button:
|
57 |
+
try:
|
58 |
+
with st.spinner("Пушечка пишется"):
|
59 |
+
if option == 'Быстрый':
|
60 |
+
result = predict(text, medium_model, medium_tokenizer, temperature=craziness)
|
61 |
+
elif option == 'Глубокий':
|
62 |
+
result = predict(text, large_model, large_tokenizer, temperature=craziness)
|
63 |
+
else:
|
64 |
+
raise st.error('Error in selectbox')
|
65 |
+
|
66 |
+
st.text_area(label='', value=result, height=1100)
|
67 |
|
68 |
+
except Exception:
|
69 |
+
st.error("Ooooops, something went wrong. Please try again and report to me, tg: @vladyur")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|