kanneboinakumar's picture
Update app.py
b28f03f verified
import streamlit as st
import joblib
# Load saved models
TF_IDF = joblib.load('tfidf_vectorizer.pkl')
svd = joblib.load('dimensionality_reduction.pkl')
RF = joblib.load('random_forest_model.pkl')
# Custom CSS for styling
st.markdown(
"""
<style>
/* Set background image for the entire app */
.stApp {
background: url('https://wallpaperaccess.com/full/1436813.jpg') no-repeat center center fixed;
background-size: cover;
}
/* Style for the title */
.stApp h1 {
background-color: rgba(0, 0, 128, 0.7); /* Semi-transparent navy blue */
color: #ffffff; /* White */
padding: 10px;
border-radius: 5px;
font-size: 2.5em;
text-align: center;
}
/* Style for input text area */
.stTextArea textarea {
background-color: rgba(255, 255, 255, 0.8); /* Semi-transparent white */
color: #000000; /* Black */
font-size: 1.2em;
}
/* Style for the button */
.stButton>button {
background-color: #4CAF50; /* Green */
color: white;
font-size: 1.2em;
border-radius: 10px;
padding: 10px 24px;
border: none;
}
/* Center the button */
.stButton {
display: flex;
justify-content: center;
}
/* Style for the output container */
.output-container {
background-color: lightpink;
color: black;
font-size: 1.5em;
padding: 15px;
border-radius: 10px;
margin-top: 20px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
width: 200%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
</style>
""",
unsafe_allow_html=True
)
# Streamlit App
st.title("Classify Game Feedback")
st.write("Enter text below to classify:")
# Text input from the user
user_input = st.text_area("Input Text", "", key="input_text", help="Type your game review here.")
# Center the predict button
col1, col2, col3 = st.columns([1,2,1])
with col2:
if st.button("Predict"):
if user_input.strip() == "":
st.warning("Please enter some text to classify.")
else:
# Transform the input text
tfidf_input = TF_IDF.transform([user_input])
reduced_input = svd.transform(tfidf_input)
# Make prediction
prediction = RF.predict(reduced_input)[0]
prediction_proba = RF.predict_proba(reduced_input)[0]
confidence = max(prediction_proba) * 100
if prediction == 1:
sentiment = "Positive"
insight = "Users appreciate the engaging gameplay and storyline."
else:
sentiment = "Negative"
insight = "Feedback suggests concerns about game performance and frequent bugs."
# Display the prediction with additional context in a single styled block
st.markdown(
f"""
<div class="output-container">
<p>The review is <strong>{sentiment}</strong> with a confidence score of {confidence:.2f}%.</p>
<p><em>Insight:</em> {insight}</p>
</div>
""",
unsafe_allow_html=True
)