Spaces:
Running
Running
BilalHasan
commited on
Commit
•
c352eb2
1
Parent(s):
bb23959
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
import json
|
4 |
+
import keras_nlp
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
fnet_classifier = load_model("Sentiments classifier.keras")
|
8 |
+
|
9 |
+
with open("vocab.json", "r") as f:
|
10 |
+
vocab = json.load(f)
|
11 |
+
|
12 |
+
seq_max_length = 512
|
13 |
+
tokenizer = keras_nlp.tokenizers.WordPieceTokenizer(
|
14 |
+
vocabulary=vocab,
|
15 |
+
lowercase=False,
|
16 |
+
sequence_length=seq_max_length,
|
17 |
+
)
|
18 |
+
|
19 |
+
def make_prediction(sentence):
|
20 |
+
tokens = tokenizer(review_example)
|
21 |
+
tokens = tf.expand_dims(tokens, 0)
|
22 |
+
prediction = fnet_classifier.predict(tokens, verbose=0)
|
23 |
+
|
24 |
+
if prediction[0][0] > 0.5:
|
25 |
+
result = "The review is POSITIVE"
|
26 |
+
else:
|
27 |
+
result = "The review is NEGATIVE"
|
28 |
+
return result
|
29 |
+
|
30 |
+
gradio_app = gr.Interface(
|
31 |
+
make_prediction,
|
32 |
+
inputs=gr.Textbox(label="Your review"),
|
33 |
+
outputs=[gr.Textbox(label="Sentiment"),
|
34 |
+
title="Positive Review or Negtaive Review",
|
35 |
+
)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
gradio_app.launch()
|