Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def classify_sentiment(text):
|
12 |
"""
|
13 |
Function to preprocess text, make predictions using the loaded model,
|
14 |
and return the predicted sentiment.
|
15 |
"""
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
# Make prediction using the loaded model
|
20 |
-
output = model(**encoded_text)
|
21 |
-
predictions = output.logits.argmax(-1)
|
22 |
-
|
23 |
-
# Map predicted class label to sentiment category
|
24 |
sentiment_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
|
25 |
-
sentiment = sentiment_mapping[
|
26 |
-
|
27 |
return sentiment
|
28 |
|
29 |
def main():
|
|
|
1 |
import streamlit as st
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing.text import Tokenizer # Assuming you used Tokenizer during training
|
4 |
|
5 |
+
# Load the pre-trained sentiment analysis model
|
6 |
+
model = load_model("sentiment_analysis_model.h5")
|
7 |
|
8 |
+
# Define a tokenizer (replace with your actual tokenization logic from training)
|
9 |
+
tokenizer = Tokenizer(num_words=5000) # Adjust vocabulary size based on your training
|
10 |
+
|
11 |
+
def preprocess_text(text):
|
12 |
+
# Preprocess text based on your training process (e.g., tokenization)
|
13 |
+
tokens = tokenizer.texts_to_sequences([text])
|
14 |
+
padded_sequence = pad_sequences(tokens, maxlen=200) # Adjust max length based on your training
|
15 |
+
return padded_sequence
|
16 |
|
17 |
def classify_sentiment(text):
|
18 |
"""
|
19 |
Function to preprocess text, make predictions using the loaded model,
|
20 |
and return the predicted sentiment.
|
21 |
"""
|
22 |
+
preprocessed_text = preprocess_text(text)
|
23 |
+
prediction = model.predict(preprocessed_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
sentiment_mapping = {0: "Negative", 1: "Neutral", 2: "Positive"}
|
25 |
+
sentiment = sentiment_mapping[prediction.argmax()]
|
|
|
26 |
return sentiment
|
27 |
|
28 |
def main():
|