OverMind0 commited on
Commit
300ed35
·
verified ·
1 Parent(s): 12777b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from tensorflow.keras.models import load_model
3
+ from tensorflow.keras.preprocessing.text import tokenizer_from_json
4
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
5
+ import json
6
+ import numpy as np
7
+
8
+ # Load tokenizer
9
+ with open("tokenizer.json", "r") as f:
10
+ data = json.load(f)
11
+ tokenizer = tokenizer_from_json(json.dumps(data))
12
+
13
+ # Parameters
14
+ max_tokens = 100 # Set this to the same as used during training
15
+
16
+ # Load model
17
+ model = load_model("review_amazon_sentiment5.h5")
18
+
19
+ # Streamlit UI
20
+ st.title("Amazon Review Sentiment Analyzer")
21
+ user_input = st.text_area("Enter an Amazon product review:")
22
+
23
+ if st.button("Analyze"):
24
+ if user_input.strip():
25
+ tokens = tokenizer.texts_to_sequences([user_input])
26
+ tokens_padded = pad_sequences(tokens, maxlen=max_tokens)
27
+ pred_prob = model.predict(tokens_padded)[0][0]
28
+ sentiment = "🟢 Positive" if pred_prob < 0.5 else "🔴 Negative"
29
+ st.markdown(f"**Sentiment:** {sentiment}")
30
+ st.markdown(f"**Confidence:** {pred_prob:.2f}")
31
+ else:
32
+ st.warning("Please enter some text to analyze.")