koshin2001's picture
๐Ÿ’„ Add model link
a5423e9
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)
"""
)