Spaces:
Runtime error
Runtime error
file
Browse filestensorflow
gradio
datasets
numpy
pickle-mixin
app
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import pickle
|
| 4 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
| 5 |
+
|
| 6 |
+
model = tf.keras.models.load_model("keras-rnn-sentiment")
|
| 7 |
+
|
| 8 |
+
with open("tokenizer.pkl", "rb") as f:
|
| 9 |
+
tokenizer = pickle.load(f)
|
| 10 |
+
|
| 11 |
+
max_length = 200
|
| 12 |
+
|
| 13 |
+
def predict_sentiment(text):
|
| 14 |
+
|
| 15 |
+
seq = tokenizer.texts_to_sequences([text])
|
| 16 |
+
padded = pad_sequences(seq, maxlen=max_length)
|
| 17 |
+
|
| 18 |
+
prediction = model.predict(padded)[0][0]
|
| 19 |
+
|
| 20 |
+
if prediction > 0.5:
|
| 21 |
+
return "Positive Review 😀"
|
| 22 |
+
else:
|
| 23 |
+
return "Negative Review 😞"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
demo = gr.Interface(
|
| 27 |
+
fn=predict_sentiment,
|
| 28 |
+
inputs=gr.Textbox(lines=3),
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="RNN Sentiment Analyzer"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|