Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,6 @@ 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
|
| 8 |
-
from keras.layers import *
|
| 9 |
-
from keras import Model
|
| 10 |
|
| 11 |
map_id = {
|
| 12 |
0: "sadness",
|
|
@@ -16,39 +13,17 @@ map_id = {
|
|
| 16 |
4: "fear",
|
| 17 |
5: "joy"
|
| 18 |
}
|
| 19 |
-
map_emotion = {
|
| 20 |
-
"sadness":0,
|
| 21 |
-
"anger":1,
|
| 22 |
-
"love":2,
|
| 23 |
-
"surprise":3,
|
| 24 |
-
"fear":4,
|
| 25 |
-
"joy":5
|
| 26 |
-
}
|
| 27 |
|
| 28 |
train = pd.read_csv('train.csv')
|
| 29 |
-
for index, row in train.iterrows():
|
| 30 |
-
row['emotion'] = map_emotion[row['emotion']]
|
| 31 |
tokenizer = Tokenizer()
|
| 32 |
tokenizer.fit_on_texts(train.text)
|
| 33 |
|
| 34 |
model = tf.keras.models.load_model('DETECTION.keras')
|
| 35 |
-
class Predict:
|
| 36 |
-
def __init__(self, model, tokenizer):
|
| 37 |
-
self.model = model
|
| 38 |
-
self.tokenizer = tokenizer
|
| 39 |
-
|
| 40 |
-
def predict(self, txt):
|
| 41 |
-
x = pad_sequences(self.tokenizer.texts_to_sequences([txt]), maxlen=30)
|
| 42 |
-
x = self.model(x)
|
| 43 |
-
x = ny.argmax(x)
|
| 44 |
-
return map_id[x]
|
| 45 |
-
predict = Predict(model, tokenizer)
|
| 46 |
-
|
| 47 |
|
| 48 |
st.title("TONE DETECTION | BCS WINTER PROJECT")
|
| 49 |
st.write("Enter a sentence to analyze text's Tone:")
|
| 50 |
|
| 51 |
user_input = st.text_input("")
|
| 52 |
if user_input:
|
| 53 |
-
result =
|
| 54 |
st.write(f"TONE: {result}")
|
|
|
|
| 4 |
import tensorflow as tf
|
| 5 |
from keras.preprocessing.text import Tokenizer
|
| 6 |
from keras.preprocessing.sequence import pad_sequences
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
map_id = {
|
| 9 |
0: "sadness",
|
|
|
|
| 13 |
4: "fear",
|
| 14 |
5: "joy"
|
| 15 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
train = pd.read_csv('train.csv')
|
|
|
|
|
|
|
| 18 |
tokenizer = Tokenizer()
|
| 19 |
tokenizer.fit_on_texts(train.text)
|
| 20 |
|
| 21 |
model = tf.keras.models.load_model('DETECTION.keras')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
st.title("TONE DETECTION | BCS WINTER PROJECT")
|
| 24 |
st.write("Enter a sentence to analyze text's Tone:")
|
| 25 |
|
| 26 |
user_input = st.text_input("")
|
| 27 |
if user_input:
|
| 28 |
+
result = "IDK"
|
| 29 |
st.write(f"TONE: {result}")
|