Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import pickle
|
| 4 |
+
import numpy as np
|
| 5 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
| 6 |
+
|
| 7 |
+
# Load the model and tokenizer
|
| 8 |
+
model = tf.keras.models.load_model('sentiment_model.keras')
|
| 9 |
+
|
| 10 |
+
with open('tokenizer.pickle', 'rb') as handle:
|
| 11 |
+
tokenizer = pickle.load(handle)
|
| 12 |
+
|
| 13 |
+
with open('max_length.txt', 'r') as f:
|
| 14 |
+
max_length = int(f.read())
|
| 15 |
+
|
| 16 |
+
def classify_sentence(sentence):
|
| 17 |
+
seq = tokenizer.texts_to_sequences([sentence])
|
| 18 |
+
padded_seq = pad_sequences(seq, maxlen=max_length)
|
| 19 |
+
prediction = model.predict(padded_seq)
|
| 20 |
+
label = "Positive" if prediction[0][0] > 0.5 else "Negative"
|
| 21 |
+
return label
|
| 22 |
+
|
| 23 |
+
# Streamlit UI
|
| 24 |
+
st.title("Restaurant Review Sentiment Analysis")
|
| 25 |
+
st.write("Enter your review in Turkish to analyze its sentiment")
|
| 26 |
+
|
| 27 |
+
user_input = st.text_area("Enter your review:")
|
| 28 |
+
|
| 29 |
+
if st.button("Analyze"):
|
| 30 |
+
if user_input:
|
| 31 |
+
result = classify_sentence(user_input)
|
| 32 |
+
st.write(f"Sentiment: {result}")
|
| 33 |
+
else:
|
| 34 |
+
st.write("Please enter a review to analyze")
|