Spaces:
Sleeping
Sleeping
Madhumitha19
commited on
Commit
•
22ec88e
1
Parent(s):
78d750d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing.text import Tokenizer
|
5 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
6 |
+
import pickle
|
7 |
+
|
8 |
+
# Load the LSTM model
|
9 |
+
lstm_model = load_model('lstm.h5')
|
10 |
+
|
11 |
+
# Load the Tokenizer used during training
|
12 |
+
with open('tokenizer.pkl', 'rb') as tokenizer_file:
|
13 |
+
tokenizer = pickle.load(tokenizer_file)
|
14 |
+
|
15 |
+
# Define class labels and their numerical mapping
|
16 |
+
class_mapping = {"Angry": 0, "Sad": 1, "Joy": 2, "Surprise": 3}
|
17 |
+
numerical_to_label = {v: k for k, v in class_mapping.items()}
|
18 |
+
|
19 |
+
st.title('Model Deployment')
|
20 |
+
|
21 |
+
# Text input for the user to enter a sequence
|
22 |
+
user_input = st.text_input('Enter a sequence:')
|
23 |
+
|
24 |
+
if st.button('Predict'):
|
25 |
+
# Tokenize and pad the user input
|
26 |
+
sequence = tokenizer.texts_to_sequences([user_input])
|
27 |
+
padded_sequence = pad_sequences(sequence, maxlen=128)
|
28 |
+
|
29 |
+
# Make predictions
|
30 |
+
prediction = lstm_model.predict(padded_sequence)
|
31 |
+
|
32 |
+
# Display the predicted probabilities and labels
|
33 |
+
st.write('Predicted Probabilities:')
|
34 |
+
for i in range(len(prediction[0])):
|
35 |
+
label = numerical_to_label[i]
|
36 |
+
st.write(f'{label}: {prediction[0][i]}')
|