Update prediction.py
Browse files- prediction.py +18 -4
prediction.py
CHANGED
@@ -1,8 +1,14 @@
|
|
1 |
import pandas as pd
|
2 |
-
|
|
|
|
|
3 |
import streamlit as st
|
4 |
|
5 |
-
model = TFSMLayer('/itsok', call_endpoint='serving_default')
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
def run():
|
@@ -10,7 +16,7 @@ def run():
|
|
10 |
st.write('This is a simple web app to predict sentiment of a text using deep learning. Input your feeling below to get the prediction.')
|
11 |
st.write('Trust me, I have analyzed it for you!')
|
12 |
|
13 |
-
|
14 |
|
15 |
def convert_to_label(pred):
|
16 |
if pred == 0:
|
@@ -31,7 +37,15 @@ def run():
|
|
31 |
return 'Unknown'
|
32 |
|
33 |
if st.button("Predict Your Feeling"):
|
34 |
-
prediction = model.predict(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
label = convert_to_label(prediction)
|
36 |
if label == 'Normal':
|
37 |
st.success('Hi! Keep up the good work! You are feeling Okay today.')
|
|
|
1 |
import pandas as pd
|
2 |
+
import numpy
|
3 |
+
# from tensorflow.keras.layers import TFSMLayer
|
4 |
+
from transformers import TFAutoModelForSequenceClassification, AutoTokenizer
|
5 |
import streamlit as st
|
6 |
|
7 |
+
# model = TFSMLayer('/itsok', call_endpoint='serving_default')
|
8 |
+
model_name='saved_model.pb'
|
9 |
+
|
10 |
+
model = TFAutoModelForSequenceClassification.from_pretrained(model_name)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
|
13 |
|
14 |
def run():
|
|
|
16 |
st.write('This is a simple web app to predict sentiment of a text using deep learning. Input your feeling below to get the prediction.')
|
17 |
st.write('Trust me, I have analyzed it for you!')
|
18 |
|
19 |
+
texts = st.text_input('Text', 'I feel so sad today')
|
20 |
|
21 |
def convert_to_label(pred):
|
22 |
if pred == 0:
|
|
|
37 |
return 'Unknown'
|
38 |
|
39 |
if st.button("Predict Your Feeling"):
|
40 |
+
# prediction = model.predict(text)
|
41 |
+
inputs = tokenizer(texts, return_tensors="tf", padding=True, truncation=True)
|
42 |
+
# Perform inference
|
43 |
+
outputs = model(inputs)
|
44 |
+
logits = outputs.logits
|
45 |
+
|
46 |
+
# If you want to get the predicted classes
|
47 |
+
prediction = tf.argmax(logits, axis=-1).numpy()
|
48 |
+
|
49 |
label = convert_to_label(prediction)
|
50 |
if label == 'Normal':
|
51 |
st.success('Hi! Keep up the good work! You are feeling Okay today.')
|