Spaces:
Running
Running
File size: 1,619 Bytes
6364f02 3bcaf40 6364f02 5641a0c a5423e9 5641a0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
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)
"""
)
|