Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,66 +25,61 @@ def get_top_emojis(text, tokenizer, model, top_n=TOP_N):
|
|
25 |
emojis = [model.config.id2label[i] for i in ranking]
|
26 |
return '\t'.join(map(str, emojis))
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
tokenizer = AutoTokenizer.from_pretrained(cur_model_name)
|
34 |
model = AutoModelForSequenceClassification.from_pretrained(cur_model_name)
|
35 |
-
|
36 |
-
st.set_page_config( # Alternate names: setup_page, page, layout
|
37 |
-
layout="centered", # Can be "centered" or "wide". In the future also "dashboard", etc.
|
38 |
-
initial_sidebar_state="auto", # Can be "auto", "expanded", "collapsed"
|
39 |
-
page_title="Emoji-motion!", # String or None. Strings get appended with "• Streamlit".
|
40 |
-
page_icon=None, # String, anything supported by st.image, or None.
|
41 |
-
)
|
42 |
-
|
43 |
-
st.title('Emoji-motion!')
|
44 |
-
|
45 |
-
example_prompts = [
|
46 |
-
"Today is going to be awesome!",
|
47 |
-
"Pity those who don't feel anything at all.",
|
48 |
-
"I envy people that know love.",
|
49 |
-
"Nature is so beautiful"]
|
50 |
-
|
51 |
-
example = st.selectbox("Choose an example", example_prompts)
|
52 |
-
|
53 |
-
# Take the message which needs to be processed
|
54 |
-
message = st.text_area("...or paste some text to see the model's predictions", example)
|
55 |
-
# st.title(message)
|
56 |
-
st.text('')
|
57 |
-
models_to_choose = [
|
58 |
-
"amazon-sagemaker-community/xlm-roberta-en-ru-emoji-v2",
|
59 |
-
"AlekseyDorkin/xlm-roberta-en-ru-emoji"
|
60 |
-
]
|
61 |
-
|
62 |
-
model_name = st.selectbox("Choose a model", models_to_choose)
|
63 |
-
if model_name != cur_model_name:
|
64 |
-
print("reloading model")
|
65 |
-
cur_model_name = model_name
|
66 |
-
tokenizer = AutoTokenizer.from_pretrained(cur_model_name)
|
67 |
-
model = AutoModelForSequenceClassification.from_pretrained(cur_model_name)
|
68 |
-
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
if __name__ == "__main__":
|
90 |
-
main()
|
|
|
25 |
emojis = [model.config.id2label[i] for i in ranking]
|
26 |
return '\t'.join(map(str, emojis))
|
27 |
|
28 |
+
|
29 |
+
cur_model_name = DEFAULT_MODEL
|
30 |
+
print("cur_model", cur_model_name)
|
31 |
+
|
32 |
+
tokenizer = AutoTokenizer.from_pretrained(cur_model_name)
|
33 |
+
model = AutoModelForSequenceClassification.from_pretrained(cur_model_name)
|
34 |
+
|
35 |
+
st.set_page_config( # Alternate names: setup_page, page, layout
|
36 |
+
layout="centered", # Can be "centered" or "wide". In the future also "dashboard", etc.
|
37 |
+
initial_sidebar_state="auto", # Can be "auto", "expanded", "collapsed"
|
38 |
+
page_title="Emoji-motion!", # String or None. Strings get appended with "• Streamlit".
|
39 |
+
page_icon=None, # String, anything supported by st.image, or None.
|
40 |
+
)
|
41 |
+
|
42 |
+
st.title('Emoji-motion!')
|
43 |
+
|
44 |
+
example_prompts = [
|
45 |
+
"Today is going to be awesome!",
|
46 |
+
"Pity those who don't feel anything at all.",
|
47 |
+
"I envy people that know love.",
|
48 |
+
"Nature is so beautiful"]
|
49 |
+
|
50 |
+
example = st.selectbox("Choose an example", example_prompts)
|
51 |
+
|
52 |
+
# Take the message which needs to be processed
|
53 |
+
message = st.text_area("...or paste some text to see the model's predictions", example)
|
54 |
+
# st.title(message)
|
55 |
+
st.text('')
|
56 |
+
models_to_choose = [
|
57 |
+
"amazon-sagemaker-community/xlm-roberta-en-ru-emoji-v2",
|
58 |
+
"AlekseyDorkin/xlm-roberta-en-ru-emoji"
|
59 |
+
]
|
60 |
+
|
61 |
+
model_name = st.selectbox("Choose a model", models_to_choose)
|
62 |
+
if model_name != cur_model_name:
|
63 |
+
print("reloading model")
|
64 |
+
cur_model_name = model_name
|
65 |
tokenizer = AutoTokenizer.from_pretrained(cur_model_name)
|
66 |
model = AutoModelForSequenceClassification.from_pretrained(cur_model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
|
69 |
+
# Define function to run when submit is clicked
|
70 |
+
def submit(message):
|
71 |
+
if len(message) > 0:
|
72 |
+
st.header(get_top_emojis(message, tokenizer=tokenizer, model=model))
|
73 |
+
else:
|
74 |
+
st.error("The text can't be empty")
|
75 |
+
|
76 |
+
# Run algo when submit button is clicked
|
77 |
+
if st.button('Submit'):
|
78 |
+
submit(message)
|
79 |
+
|
80 |
+
st.text('')
|
81 |
+
st.markdown(
|
82 |
+
'''<span style="color:blue; font-size:10px">App created by [@AlekseyDorkin](https://huggingface.co/AlekseyDorkin)
|
83 |
+
and [@akshay7](https://huggingface.co/akshay7)</span>''',
|
84 |
+
unsafe_allow_html=True,
|
85 |
+
)
|
|
|
|
|
|