Spaces:
Build error
Build error
Download app.py from Akshara10/Sentiment_Analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/Akshara10/Sentiment_Analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/Akshara10/Sentiment_Analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Akshara10/Sentiment_Analysis/resolve/main/app.py
1.01 kB
| import gradio as gd | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing.text import Tokenizer | |
| from tensorflow.keras.preprocessing.sequence import pad_sequences | |
| import pickle | |
| model = load_model("sentiment_analysis_LSTM.h5") | |
| with open('tokenizer.pickle', 'rb') as handle: | |
| tokenizer = pickle.load(handle) | |
| def preprocess(text): | |
| sequences = tokenizer.texts_to_sequences([text]) | |
| padded_sequences = pad_sequences(sequences, maxlen = 250) | |
| return padded_sequences | |
| def predict(text): | |
| processed_text = preprocess(text) | |
| prediction = model.predict(processed_text) | |
| return "Positive" if prediction[0][0] > 0.5 else "Negative" | |
| gradio = gd.Interface( | |
| fn = predict, | |
| inputs = gd.Textbox(lines = 2, placeholder = 'Enter a sentence here...'), | |
| outputs = 'text', | |
| title = "Sentiment Analysis", | |
| description = "Enter a sentence to predict its sentiment. The model will predict it as Positive or Negative ") | |
| gradio.launch(share = True) |