junming-qiu commited on
Commit
da9b562
1 Parent(s): 4902206

final fine tuned

Browse files
Files changed (2) hide show
  1. README.md +1 -0
  2. app.py +19 -5
README.md CHANGED
@@ -14,6 +14,7 @@ pinned: false
14
  <ol>
15
  <li>Milestone 1: Setup Instructions</li>
16
  <li>Milestone 2: Hugging Face Space: <a href="https://huggingface.co/spaces/junming-qiu/toxic-tweets-milestone-2">Hugging Face Milestone 2 Demo</a></li>
 
17
  </ol>
18
 
19
  <h1>Motivation</h1>
 
14
  <ol>
15
  <li>Milestone 1: Setup Instructions</li>
16
  <li>Milestone 2: Hugging Face Space: <a href="https://huggingface.co/spaces/junming-qiu/toxic-tweets-milestone-2">Hugging Face Milestone 2 Demo</a></li>
17
+ <li>Milestone 3: Fine Tuned Toxic Comment model: <a href="https://huggingface.co/spaces/junming-qiu/toxic-tweets-milestone-2">Hugging Face Milestone 3 Demo</a></li>
18
  </ol>
19
 
20
  <h1>Motivation</h1>
app.py CHANGED
@@ -1,18 +1,17 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
- from transformers import BertTokenizer, BertForSequenceClassification
5
  from huggingface_hub.inference_api import InferenceApi
6
  import os
7
 
8
- models = ["cardiffnlp/twitter-xlm-roberta-base-sentiment", "nlptown/bert-base-multilingual-uncased-sentiment", "Tatyana/rubert-base-cased-sentiment-new", "junming-qiu/BertToxicClassifier"]
9
 
10
 
11
 
12
  st.title('Sentiment Analysis Demo')
13
  with st.form("form"):
14
  selection = st.selectbox('Select Transformer:', models)
15
- text = st.text_input('Enter text: ', "I do not like to walk")
16
  submitted = st.form_submit_button('Submit')
17
 
18
  if submitted:
@@ -20,11 +19,26 @@ with st.form("form"):
20
 
21
  if model_name == "junming-qiu/BertToxicClassifier":
22
  API_TOKEN=os.environ['API-KEY']
 
23
  inference = InferenceApi(repo_id=model_name, token=API_TOKEN)
24
  predictions = inference(inputs=text)[0]
25
  predictions = sorted(predictions, key=lambda x: x['score'], reverse=True)
26
- st.write(predictions[0]['label']+":", predictions[0]['score'])
27
- st.write(predictions[1]['label']+":", predictions[1]['score'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  else:
29
 
30
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
 
1
  import streamlit as st
2
  from transformers import pipeline
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
4
  from huggingface_hub.inference_api import InferenceApi
5
  import os
6
 
7
+ models = ["junming-qiu/BertToxicClassifier", "cardiffnlp/twitter-xlm-roberta-base-sentiment", "nlptown/bert-base-multilingual-uncased-sentiment", "Tatyana/rubert-base-cased-sentiment-new"]
8
 
9
 
10
 
11
  st.title('Sentiment Analysis Demo')
12
  with st.form("form"):
13
  selection = st.selectbox('Select Transformer:', models)
14
+ text = st.text_input('Enter text: ', "I hate people who walk")
15
  submitted = st.form_submit_button('Submit')
16
 
17
  if submitted:
 
19
 
20
  if model_name == "junming-qiu/BertToxicClassifier":
21
  API_TOKEN=os.environ['API-KEY']
22
+
23
  inference = InferenceApi(repo_id=model_name, token=API_TOKEN)
24
  predictions = inference(inputs=text)[0]
25
  predictions = sorted(predictions, key=lambda x: x['score'], reverse=True)
26
+
27
+ hide_table_row_index = """
28
+ <style>
29
+ thead tr th:first-child {display:none}
30
+ tbody th {display:none}
31
+ </style>
32
+ """
33
+
34
+ st.markdown(hide_table_row_index, unsafe_allow_html=True)
35
+
36
+ output = [
37
+ {"tweet": text,
38
+ "label": predictions[0]['label'],
39
+ "score" : predictions[0]['score']},
40
+ ]
41
+ st.table(output)
42
  else:
43
 
44
  model = AutoModelForSequenceClassification.from_pretrained(model_name)