Spaces:
Runtime error
Runtime error
Download app.py from mithunmiracle27/mithu: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/mithunmiracle27/mithu/resolve/main/app.py
- Command line
-
hf download hf://spaces/mithunmiracle27/mithu/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mithunmiracle27/mithu/resolve/main/app.py
1.13 kB
| # -*- coding: utf-8 -*- | |
| """Untitled3.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1nlpl1EkIfUOEr5pWGM7HWx_TBlZTMe-L | |
| """ | |
| import gradio as gr | |
| import tensorflow as tf | |
| import pickle | |
| from tensorflow.keras.preprocessing.sequence import pad_sequences | |
| # Load trained model | |
| model = tf.keras.models.load_model("keras-rnn-sentiment") | |
| # Load tokenizer | |
| with open("tokenizer.pkl", "rb") as f: | |
| tokenizer = pickle.load(f) | |
| max_length = 200 | |
| def predict_sentiment(text): | |
| seq = tokenizer.texts_to_sequences([text]) | |
| padded = pad_sequences(seq, maxlen=max_length) | |
| prediction = model.predict(padded)[0][0] | |
| if prediction > 0.5: | |
| return f"Positive Review ๐ (confidence {prediction:.2f})" | |
| else: | |
| return f"Negative Review ๐ (confidence {1-prediction:.2f})" | |
| interface = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs=gr.Textbox(lines=3, placeholder="Enter a movie review..."), | |
| outputs="text", | |
| title="RNN Sentiment Analyzer", | |
| description="Enter a sentence and the RNN model will predict sentiment." | |
| ) | |
| interface.launch() |