Spaces:
Running
Running
import streamlit as st | |
import inference | |
import pandas as pd | |
import const | |
st.title("Japanese to Emotions") | |
st.write( | |
"I fine-tuned the BERT-based distillation model for classification of Japanese text." | |
) | |
if "input_text" not in st.session_state: | |
st.session_state.input_text = "" | |
input_text = st.text_area( | |
"Japanese text", value=st.session_state.input_text, max_chars=512 | |
) | |
suggestions = ["ไปๆฅใฏๆ็ฌใจๆฃๆญฉใใ", "็ซใซใใง่กใใใ", "่ช่ปข่ป็ใพใใ"] | |
COLUMNS_NUM = len(suggestions) | |
cols = st.columns(COLUMNS_NUM) | |
for i, suggestion in enumerate(suggestions): | |
with cols[i]: | |
if st.button(suggestion, use_container_width=True): | |
st.session_state.input_text = suggestion | |
st.rerun() | |
if input_text: | |
probs_dict = inference.exec(input_text) | |
label_dict = { | |
const.EMOTIONS[0]: "๐ Joy", | |
const.EMOTIONS[1]: "๐ข Sadness", | |
const.EMOTIONS[2]: "๐ฎ Anticipation", | |
const.EMOTIONS[3]: "๐ฒ Surprise", | |
const.EMOTIONS[4]: "๐ Anger", | |
const.EMOTIONS[5]: "๐จ Fear", | |
const.EMOTIONS[6]: "๐ Disgust", | |
const.EMOTIONS[7]: "๐ Trust", | |
} | |
df = pd.DataFrame( | |
{ | |
"Emotion": label_dict.values(), | |
"Probs": [probs_dict[emotion] for emotion in const.EMOTIONS], | |
} | |
) | |
st.bar_chart(df.set_index("Emotion"), horizontal=True) | |
st.write( | |
""" | |
- [Model](https://huggingface.co/koshin2001/Japanese-to-emotions) | |
- [Blog](https://zenn.dev/koshin/articles/6b27acdf8bbe01) | |
- [GitHub](https://github.com/koshin01/emotion_classification) | |
""" | |
) | |