Spaces:
Runtime error
Runtime error
ADD: caching of models
Browse files
app.py
CHANGED
@@ -3,34 +3,51 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
|
6 |
-
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
st.set_page_config( # Alternate names: setup_page, page, layout
|
9 |
layout="centered", # Can be "centered" or "wide". In the future also "dashboard", etc.
|
10 |
initial_sidebar_state="auto", # Can be "auto", "expanded", "collapsed"
|
11 |
page_title="Emoji-motion!", # String or None. Strings get appended with "• Streamlit".
|
12 |
page_icon=None, # String, anything supported by st.image, or None.
|
13 |
)
|
14 |
-
|
15 |
st.title('Emoji-motion!')
|
16 |
-
|
17 |
example_prompts = [
|
18 |
-
"
|
19 |
-
"
|
20 |
-
"I
|
21 |
-
"
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
|
|
|
|
|
25 |
# Take the message which needs to be processed
|
26 |
-
message = st.text_area(
|
27 |
# st.title(message)
|
28 |
st.text('')
|
29 |
-
models_to_choose = [
|
30 |
-
|
|
|
|
|
|
|
31 |
BASE_MODEL = st.selectbox("Choose a model", models_to_choose)
|
32 |
TOP_N = 5
|
33 |
|
|
|
34 |
def preprocess(text):
|
35 |
new_text = []
|
36 |
for t in text.split(" "):
|
@@ -55,22 +72,25 @@ def main():
|
|
55 |
ranking = ranking.squeeze()[::-1][:top_n]
|
56 |
emojis = [model.config.id2label[i] for i in ranking]
|
57 |
return ', '.join(map(str, emojis))
|
58 |
-
|
|
|
59 |
# Define function to run when submit is clicked
|
60 |
def submit(message):
|
61 |
-
if len(message)>0:
|
62 |
-
st.header(get_top_emojis(message))
|
63 |
else:
|
64 |
st.error("The text can't be empty")
|
65 |
-
|
66 |
# Run algo when submit button is clicked
|
67 |
-
if
|
68 |
submit(message)
|
69 |
-
|
70 |
st.text('')
|
71 |
-
st.markdown(
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
if __name__ == "__main__":
|
76 |
main()
|
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
|
6 |
+
TOP_N = 5
|
7 |
|
8 |
+
def main():
|
9 |
+
print("cur_model", cur_model_name)
|
10 |
+
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(cur_model_name)
|
12 |
+
model = AutoModelForSequenceClassification.from_pretrained(cur_model_name)
|
13 |
+
|
14 |
st.set_page_config( # Alternate names: setup_page, page, layout
|
15 |
layout="centered", # Can be "centered" or "wide". In the future also "dashboard", etc.
|
16 |
initial_sidebar_state="auto", # Can be "auto", "expanded", "collapsed"
|
17 |
page_title="Emoji-motion!", # String or None. Strings get appended with "• Streamlit".
|
18 |
page_icon=None, # String, anything supported by st.image, or None.
|
19 |
)
|
20 |
+
|
21 |
st.title('Emoji-motion!')
|
22 |
+
|
23 |
example_prompts = [
|
24 |
+
"it's pretty depressing when u hit pan on ur favourite highlighter",
|
25 |
+
"After what just happened. In need to smoke.",
|
26 |
+
"I've never been happier. I'm laying awake as I watch @user sleep. Thanks for making me happy again, babe.",
|
27 |
+
"@user is the man",
|
28 |
+
"Поприветствуем моего нового читателя @user",
|
29 |
+
"сегодня у одной крутой бичи день рождения! @user поздравляю тебя с днем рождения! будь самой-самой счастливой,красота:* море любви тебе",
|
30 |
+
"Никогда не явствовала себя ужаснее, чем сейчас:( я просто раздавленна",
|
31 |
+
"Самое ужасное - это ожидание результатов",
|
32 |
+
"печально что заряд одинаково фигово держится(",
|
33 |
+
]
|
34 |
+
|
35 |
|
36 |
+
example = st.selectbox("Choose an example", example_prompts)
|
37 |
+
|
38 |
# Take the message which needs to be processed
|
39 |
+
message = st.text_area("...or paste some text to see the model's predictions", example)
|
40 |
# st.title(message)
|
41 |
st.text('')
|
42 |
+
models_to_choose = [
|
43 |
+
"amazon-sagemaker-community/xlm-roberta-en-ru-emoji-v2",
|
44 |
+
"AlekseyDorkin/xlm-roberta-en-ru-emoji"
|
45 |
+
]
|
46 |
+
|
47 |
BASE_MODEL = st.selectbox("Choose a model", models_to_choose)
|
48 |
TOP_N = 5
|
49 |
|
50 |
+
|
51 |
def preprocess(text):
|
52 |
new_text = []
|
53 |
for t in text.split(" "):
|
|
|
72 |
ranking = ranking.squeeze()[::-1][:top_n]
|
73 |
emojis = [model.config.id2label[i] for i in ranking]
|
74 |
return ', '.join(map(str, emojis))
|
75 |
+
|
76 |
+
|
77 |
# Define function to run when submit is clicked
|
78 |
def submit(message):
|
79 |
+
if len(message) > 0:
|
80 |
+
st.header(get_top_emojis(message, tokenizer=tokenizer, model=model))
|
81 |
else:
|
82 |
st.error("The text can't be empty")
|
83 |
+
|
84 |
# Run algo when submit button is clicked
|
85 |
+
if st.button('Submit'):
|
86 |
submit(message)
|
87 |
+
|
88 |
st.text('')
|
89 |
+
st.markdown(
|
90 |
+
'''<span style="color:blue; font-size:10px">App created by [@AlekseyDorkin](https://huggingface.co/AlekseyDorkin)
|
91 |
+
and [@akshay7](https://huggingface.co/akshay7)</span>''',
|
92 |
+
unsafe_allow_html=True,
|
93 |
+
)
|
94 |
+
|
95 |
if __name__ == "__main__":
|
96 |
main()
|