Commit
·
a7f2f89
1
Parent(s):
2f9f9d9
changed gradio interface
Browse files
app.py
CHANGED
@@ -2,29 +2,30 @@ import tensorflow as tf
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
|
5 |
-
# Load the
|
6 |
-
model =
|
7 |
|
8 |
-
# Define
|
9 |
-
def
|
10 |
# Tokenize the text
|
11 |
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000)
|
12 |
tokenizer.fit_on_texts(text)
|
13 |
-
|
14 |
-
# Pad the sequences to a fixed length
|
15 |
-
max_len = 30
|
16 |
-
text = tf.keras.preprocessing.sequence.pad_sequences(text, maxlen=max_len)
|
17 |
-
return text
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Define the Gradio interface
|
30 |
interface = gr.Interface(
|
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
|
5 |
+
# Load the saved model
|
6 |
+
model = load_model('sentimentality.h5')
|
7 |
|
8 |
+
# Define the function to preprocess the text
|
9 |
+
def preprocess(text):
|
10 |
# Tokenize the text
|
11 |
tokenizer = tf.keras.preprocessing.text.Tokenizer(num_words=10000)
|
12 |
tokenizer.fit_on_texts(text)
|
13 |
+
sequences = tokenizer.texts_to_sequences(text)
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Pad the sequences to a fixed length of 30
|
16 |
+
padded_sequences = tf.keras.preprocessing.sequence.pad_sequences(sequences, maxlen=30, padding='post')
|
17 |
+
|
18 |
+
return np.array(padded_sequences)
|
19 |
+
|
20 |
+
# Define the function to make predictions on the text
|
21 |
+
def sentiment_analysis(text):
|
22 |
+
preprocessed_text = preprocess([text])
|
23 |
+
prediction = model.predict(preprocessed_text)[0][0]
|
24 |
+
|
25 |
+
if prediction >= 0.5:
|
26 |
+
return "positive"
|
27 |
+
else:
|
28 |
+
return "negative"
|
29 |
|
30 |
# Define the Gradio interface
|
31 |
interface = gr.Interface(
|