w11wo commited on
Commit
aa805a6
โ€ข
1 Parent(s): a2eafc7

initial commit

Browse files
Files changed (3) hide show
  1. README.md +4 -4
  2. app.py +63 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Roberta Indonesian
3
- emoji: ๐Ÿจ
4
- colorFrom: yellow
5
- colorTo: indigo
6
  sdk: streamlit
7
  app_file: app.py
8
  pinned: false
 
1
  ---
2
+ title: RoBERTa Indonesian
3
+ emoji: ๐Ÿ‡ฎ๐Ÿ‡ฉ
4
+ colorFrom: red
5
+ colorTo: white
6
  sdk: streamlit
7
  app_file: app.py
8
  pinned: false
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from huggingface_hub import InferenceApi
3
+ import pandas as pd
4
+ from transformers import pipeline
5
+
6
+ STYLE = """
7
+ <style>
8
+ img {
9
+ max-width: 100%;
10
+ }
11
+
12
+ th {
13
+ text-align: left!important
14
+ }
15
+ </style>
16
+ """
17
+ MASK_TOKEN = "<mask>"
18
+
19
+
20
+ def display_table(df):
21
+ st.subheader("Top 5 Prediction.")
22
+ df.drop(columns=["token", "token_str"], inplace=True)
23
+ df = df.style.set_properties(subset=["sequence", "score"], **{"text-align": "left"})
24
+ st.table(df)
25
+
26
+
27
+ def main():
28
+ st.markdown(STYLE, unsafe_allow_html=True)
29
+ st.title("Indonesian RoBERTa Base")
30
+ user_input = st.text_input("Insert a sentence to predict with a mask token: <mask>")
31
+ mask_api = InferenceApi("flax-community/indonesian-roberta-base")
32
+
33
+ emot_name = "StevenLimcorn/indonesian-roberta-base-emotion-classifier"
34
+ emot_pipeline = pipeline("sentiment-analysis", model=emot_name, tokenizer=emot_name)
35
+
36
+ if len(user_input) > 0:
37
+ try:
38
+ user_input.index(MASK_TOKEN)
39
+ except ValueError:
40
+ st.error("Please enter a sentence with the correct mask token: <mask>")
41
+ else:
42
+ # A List of dict with keys: sequence, score, token, token_str
43
+ result = mask_api(inputs=user_input)
44
+ df = pd.DataFrame(result)
45
+ display_table(df)
46
+
47
+ # emot
48
+ st.subheader("Emotion Analysis of the Top 5 Prediction")
49
+ emot_df = pd.DataFrame(columns=["sequence", "label", "score"])
50
+ for sequence in df["sequence"].values:
51
+ emot_output = emot_pipeline(sequence)
52
+
53
+ result_dict = {"sequence": sequence}
54
+ result_dict.update(emot_output[0])
55
+ emot_df = emot_df.append(result_dict, ignore_index=True)
56
+
57
+ emot_df = emot_df.style.set_properties(
58
+ subset=["sequence", "label", "score"], **{"text-align": "left"}
59
+ )
60
+ st.table(emot_df)
61
+
62
+
63
+ main()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ huggingface_hub
3
+ torch
4
+ jax
5
+ flax
6
+ transformers
7
+ pandas