Madhumitha19's picture
Update app.py
203b308
raw
history blame
2.69 kB
import streamlit as st
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle
# Load the LSTM model
lstm_model = load_model('lstm.h5')
# Load the Tokenizer used during training
with open('tokenizer.pkl', 'rb') as tokenizer_file:
tokenizer = pickle.load(tokenizer_file)
# Define class labels and their numerical mapping
class_mapping = {"Angry": 0, "Sad": 1, "Joy": 2, "Surprise": 3}
numerical_to_label = {v: k for k, v in class_mapping.items()}
st.set_page_config(layout = "wide")
st.title('VibeConnect ๐Ÿ˜๐Ÿ˜‹๐Ÿคช')
st.markdown(
"""
<style>
div.stElement {
text-align: center;
}
</style>
""",
unsafe_allow_html=True
)
# Define the emojis you want to use
emojis = ["๐Ÿคฃ","๐Ÿฅฒ","๐Ÿฅน","๐Ÿ˜‡","๐Ÿ˜","๐Ÿ˜‹","๐Ÿคช","๐Ÿคฉ","๐Ÿฅณ","๐Ÿ˜ญ","๐Ÿ˜ก","๐Ÿ˜ฆ","๐Ÿ˜ง","๐Ÿ˜ฎ","๐Ÿฅด","๐Ÿคฎ","๐Ÿคง","๐Ÿ˜ท"]
# Create a string of emojis to use as the background
background_emojis = " ".join(emojis * 10) # Repeat the emojis to cover the background
# Use HTML and CSS to set the background
background_style = f"""
<style>
body {{
margin: 0;
padding: 0;
background: linear-gradient(to right, #ffecd2, #fcb69f);
font-size: 30px;
background-size: 100% 100%;
background-attachment: fixed;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}}
.content {{
margin: 0;
padding: 20px;
border-radius: 10px;
text-align: center;
background: rgba(255, 255, 255, 0.8);
opacity: 0.3;
width: 100%;
height: 100%;
}}
</style>
<div class="content">
{background_emojis}
</div>
"""
# Set the HTML as the app's background
st.markdown(background_style, unsafe_allow_html=True)
# Text input for the user to enter a sequence
user_input = st.text_input('Enter a Text:')
if st.button('Predict'):
# Tokenize and pad the user input
sequence = tokenizer.texts_to_sequences([user_input])
padded_sequence = pad_sequences(sequence, maxlen=128)
# Make predictions
prediction = lstm_model.predict(padded_sequence)
emojis = ["๐Ÿ˜ก", "๐Ÿ˜ญ", "๐Ÿ˜„", "๐Ÿ˜ฏ"]
threshold = 0.5
# Display the label
for i in range(len(prediction[0])):
label = numerical_to_label[i]
probability = prediction[0][i]
if probability > threshold:
st.write(f'{label}{emojis[i]}')