Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as ny
|
|
|
|
| 4 |
from keras.preprocessing.text import Tokenizer
|
| 5 |
from keras.preprocessing.sequence import pad_sequences
|
| 6 |
from sklearn.preprocessing import LabelEncoder
|
|
@@ -15,42 +16,14 @@ map_id = {
|
|
| 15 |
4: "fear",
|
| 16 |
5: "joy"
|
| 17 |
}
|
| 18 |
-
map_emotion = {
|
| 19 |
-
"sadness": 0,
|
| 20 |
-
"anger": 1,
|
| 21 |
-
"love": 2,
|
| 22 |
-
"surprise": 3,
|
| 23 |
-
"fear": 4,
|
| 24 |
-
"joy": 5
|
| 25 |
-
}
|
| 26 |
|
| 27 |
train = pd.read_csv('train.csv')
|
| 28 |
for index, row in train.iterrows():
|
| 29 |
row['emotion'] = map_emotion[row['emotion']]
|
| 30 |
tokenizer = Tokenizer()
|
| 31 |
tokenizer.fit_on_texts(train.text)
|
| 32 |
-
Length = len(tokenizer.word_index) + 1
|
| 33 |
-
x_train = pad_sequences(tokenizer.texts_to_sequences(train.text), maxlen=30)
|
| 34 |
-
encoder = LabelEncoder()
|
| 35 |
-
encoder.fit(train["emotion"].to_list())
|
| 36 |
-
y_train = encoder.transform(train["emotion"].to_list())
|
| 37 |
-
y_train = y_train.reshape(-1, 1)
|
| 38 |
-
|
| 39 |
-
embedding_layer = Embedding(Length,
|
| 40 |
-
64,
|
| 41 |
-
input_length=30)
|
| 42 |
-
|
| 43 |
-
input_seq = Input(shape=(x_train.shape[1],))
|
| 44 |
-
x = embedding_layer(input_seq)
|
| 45 |
-
x = LSTM(10, return_sequences=True) (x)
|
| 46 |
-
x = Flatten() (x)
|
| 47 |
-
output = Dense(encoder.classes_.shape[0], activation="softmax") (x)
|
| 48 |
|
| 49 |
-
model =
|
| 50 |
-
model.compile(optimizer='adam',
|
| 51 |
-
loss="sparse_categorical_crossentropy",
|
| 52 |
-
metrics=["accuracy"])
|
| 53 |
-
model.fit(x_train, y_train, epochs=20, batch_size=32)
|
| 54 |
class Predict:
|
| 55 |
def __init__(self, model, tokenizer):
|
| 56 |
self.model = model
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as ny
|
| 4 |
+
import tensorflow as tf
|
| 5 |
from keras.preprocessing.text import Tokenizer
|
| 6 |
from keras.preprocessing.sequence import pad_sequences
|
| 7 |
from sklearn.preprocessing import LabelEncoder
|
|
|
|
| 16 |
4: "fear",
|
| 17 |
5: "joy"
|
| 18 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
train = pd.read_csv('train.csv')
|
| 21 |
for index, row in train.iterrows():
|
| 22 |
row['emotion'] = map_emotion[row['emotion']]
|
| 23 |
tokenizer = Tokenizer()
|
| 24 |
tokenizer.fit_on_texts(train.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
model = tf.keras.models.load_model('DETECTION.keras')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
class Predict:
|
| 28 |
def __init__(self, model, tokenizer):
|
| 29 |
self.model = model
|