Spaces:
Build error
Build error
Download app.py from BilalHasan/Sentiment-Analysis: direct link, hf CLI and curl.
- Browser
- Download file 943 Bytes
-
https://huggingface.co/spaces/BilalHasan/Sentiment-Analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/BilalHasan/Sentiment-Analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/BilalHasan/Sentiment-Analysis/resolve/main/app.py
943 Bytes
| import tensorflow as tf | |
| from tensorflow.keras.models import load_model | |
| import json | |
| import keras_nlp | |
| import gradio as gr | |
| fnet_classifier = load_model("Sentiments classifier.keras") | |
| with open("vocab.json", "r") as f: | |
| vocab = json.load(f) | |
| seq_max_length = 512 | |
| tokenizer = keras_nlp.tokenizers.WordPieceTokenizer( | |
| vocabulary=vocab, | |
| lowercase=False, | |
| sequence_length=seq_max_length, | |
| ) | |
| def make_prediction(sentence): | |
| tokens = tokenizer(sentence) | |
| tokens = tf.expand_dims(tokens, 0) | |
| prediction = fnet_classifier.predict(tokens, verbose=0) | |
| if prediction[0][0] > 0.5: | |
| result = "The review is POSITIVE" | |
| else: | |
| result = "The review is NEGATIVE" | |
| return result | |
| gradio_app = gr.Interface( | |
| make_prediction, | |
| inputs=gr.Textbox(label="Your review"), | |
| outputs=gr.Textbox(label="Sentiment"), | |
| title="Positive Review or Negtaive Review", | |
| ) | |
| if __name__ == "__main__": | |
| gradio_app.launch() |