kaixinwang commited on
Commit
0ed8f63
·
1 Parent(s): ae17a67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -1,9 +1,22 @@
1
  import streamlit as st
 
 
2
 
3
  x = st.header("Welcome to the STEM NLP application!")
4
 
5
- x = st.slider('Select a value')
6
- st.write(x, 'squared is', x * x)
 
 
7
 
8
  x = st.text_input("Type in your review here:")
9
- st.write("Your review is:", x)
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ import tensorflow as tf
4
 
5
  x = st.header("Welcome to the STEM NLP application!")
6
 
7
+ model = TFDistilBertForSequenceClassification.from_pretrained("kaixinwang/NLP")
8
+
9
+ MODEL_NAME_1 = 'distilbert-base-uncased'
10
+ tokenizer = DistilBertTokenizer.from_pretrained(MODEL_NAME_1)
11
 
12
  x = st.text_input("Type in your review here:")
13
+ st.write("Your review is:", x)
14
+ encoding = tokenizer(x, truncation=True, padding=True)
15
+ encoded = tf.data.Dataset.from_tensor_slices((dict(encoding), 1)
16
+ preds = model.predict(encoded.batch(1)).logits
17
+ prob = tf.nn.softmax(preds, axis=1).numpy()
18
+ prob_max = np.argmax(prob, axis=1)
19
+ st.write("Sentiment:", prob_max, "Score:", prob[prob_max])
20
+
21
+ # x = st.slider('Select a value')
22
+ # st.write(x, 'squared is', x * x)