Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- prediction.py +19 -19
prediction.py
CHANGED
|
@@ -19,29 +19,29 @@ def get_feeling(number):
|
|
| 19 |
|
| 20 |
# Load the model function
|
| 21 |
def load_model():
|
| 22 |
-
|
| 23 |
|
| 24 |
-
st.session_state
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def app():
|
| 27 |
st.header('Prediction', divider='rainbow')
|
| 28 |
|
| 29 |
user_input = st.text_input("Enter your text here:")
|
| 30 |
-
if '
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
predicted_class = np.argmax(predictions, axis=1)
|
| 43 |
-
the_sentiment = predicted_class[0]
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 19 |
|
| 20 |
# Load the model function
|
| 21 |
def load_model():
|
| 22 |
+
return tf.keras.models.load_model('model.keras', custom_objects={'KerasLayer': tf_hub.KerasLayer})
|
| 23 |
|
| 24 |
+
if 'the_model' not in st.session_state:
|
| 25 |
+
with st.spinner("Loading the model, please wait..."):
|
| 26 |
+
st.session_state.the_model = load_model()
|
| 27 |
|
| 28 |
def app():
|
| 29 |
st.header('Prediction', divider='rainbow')
|
| 30 |
|
| 31 |
user_input = st.text_input("Enter your text here:")
|
| 32 |
+
if st.button('Predict', type="secondary"):
|
| 33 |
+
data = {
|
| 34 |
+
"text_processed": [
|
| 35 |
+
user_input
|
| 36 |
+
]
|
| 37 |
+
}
|
| 38 |
+
df = pd.DataFrame(data)
|
| 39 |
+
with st.spinner("Making prediction..."):
|
| 40 |
+
# Replace with your preprocessing and prediction code
|
| 41 |
+
predictions = st.session_state.the_model.predict(df)
|
| 42 |
+
predicted_class = np.argmax(predictions, axis=1)
|
| 43 |
+
the_sentiment = predicted_class[0]
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
st.write(f"We have predicted that the sentiment of this text is {get_feeling(the_sentiment)}")
|
| 46 |
+
else:
|
| 47 |
+
st.write("Click the button to predict!")
|