w11wo commited on
Commit
3017b00
โ€ข
1 Parent(s): b837ff1

added classifier config

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -21,12 +21,15 @@ td {
21
 
22
  MASK_TOKEN = "<mask>"
23
 
24
- EMOTION_MAP = {
25
  "anger": "๐Ÿ˜ก",
26
  "fear": "๐Ÿ˜ฑ",
27
  "happy": "๐Ÿ˜„",
28
  "love": "๐Ÿ˜",
29
  "sadness": "๐Ÿ˜ญ",
 
 
 
30
  }
31
 
32
 
@@ -37,7 +40,6 @@ def display_table(df: pd.DataFrame, subheader: str):
37
 
38
  def setup():
39
  st.markdown(STYLE, unsafe_allow_html=True)
40
- # st.title("")
41
  st.markdown(
42
  """
43
  # ๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesian RoBERTa Base
@@ -45,11 +47,18 @@ def setup():
45
  Demo Powered by [Indonesian RoBERTa Base](https://huggingface.co/flax-community/indonesian-roberta-base).
46
  """
47
  )
 
48
 
49
 
50
  def main():
51
  setup()
52
 
 
 
 
 
 
 
53
  user_input = st.text_input(
54
  f"Insert a sentence to predict with a {MASK_TOKEN} token // Masukkan kalimat untuk diisi dengan token {MASK_TOKEN}",
55
  value=f"Gila! Hari ini aku {MASK_TOKEN} banget..",
@@ -58,8 +67,11 @@ def main():
58
  mlm_model = "flax-community/indonesian-roberta-base"
59
  mask_api = InferenceApi(mlm_model)
60
 
61
- sa_model = "StevenLimcorn/indonesian-roberta-base-emotion-classifier"
62
- # sa_model = "w11wo/indonesian-roberta-base-sentiment-classifier"
 
 
 
63
  sa_pipeline = pipeline("sentiment-analysis", model=sa_model, tokenizer=sa_model)
64
 
65
  if len(user_input) > 0:
@@ -89,7 +101,7 @@ def main():
89
  result_dict.update(sa_output[0])
90
  sa_df = sa_df.append(result_dict, ignore_index=True)
91
 
92
- sa_df["label"] = sa_df["label"].apply(lambda x: x + " " + EMOTION_MAP[x])
93
  sa_df_styled = sa_df.copy(deep=False)
94
  sa_df_styled = sa_df_styled.style.set_properties(
95
  subset=["sequence", "label", "score"], **{"text-align": "left"}
21
 
22
  MASK_TOKEN = "<mask>"
23
 
24
+ EMOJI_MAP = {
25
  "anger": "๐Ÿ˜ก",
26
  "fear": "๐Ÿ˜ฑ",
27
  "happy": "๐Ÿ˜„",
28
  "love": "๐Ÿ˜",
29
  "sadness": "๐Ÿ˜ญ",
30
+ "positive": "๐Ÿค—",
31
+ "negative": "๐Ÿ˜ค",
32
+ "neutral": "๐Ÿ˜",
33
  }
34
 
35
 
40
 
41
  def setup():
42
  st.markdown(STYLE, unsafe_allow_html=True)
 
43
  st.markdown(
44
  """
45
  # ๐Ÿ‡ฎ๐Ÿ‡ฉ Indonesian RoBERTa Base
47
  Demo Powered by [Indonesian RoBERTa Base](https://huggingface.co/flax-community/indonesian-roberta-base).
48
  """
49
  )
50
+ st.sidebar.subheader("Settings")
51
 
52
 
53
  def main():
54
  setup()
55
 
56
+ analyze = st.sidebar.selectbox(
57
+ "What should we analyze?",
58
+ ("Emotion", "Sentiment"),
59
+ help="Classifier model to choose for text analysis",
60
+ )
61
+
62
  user_input = st.text_input(
63
  f"Insert a sentence to predict with a {MASK_TOKEN} token // Masukkan kalimat untuk diisi dengan token {MASK_TOKEN}",
64
  value=f"Gila! Hari ini aku {MASK_TOKEN} banget..",
67
  mlm_model = "flax-community/indonesian-roberta-base"
68
  mask_api = InferenceApi(mlm_model)
69
 
70
+ if analyze == "Emotion":
71
+ sa_model = "StevenLimcorn/indonesian-roberta-base-emotion-classifier"
72
+ elif analyze == "Sentiment":
73
+ sa_model = "w11wo/indonesian-roberta-base-sentiment-classifier"
74
+
75
  sa_pipeline = pipeline("sentiment-analysis", model=sa_model, tokenizer=sa_model)
76
 
77
  if len(user_input) > 0:
101
  result_dict.update(sa_output[0])
102
  sa_df = sa_df.append(result_dict, ignore_index=True)
103
 
104
+ sa_df["label"] = sa_df["label"].apply(lambda x: x + " " + EMOJI_MAP[x])
105
  sa_df_styled = sa_df.copy(deep=False)
106
  sa_df_styled = sa_df_styled.style.set_properties(
107
  subset=["sequence", "label", "score"], **{"text-align": "left"}