| import streamlit as st |
| import joblib |
|
|
| |
| TF_IDF = joblib.load('tfidf_vectorizer.pkl') |
| svd = joblib.load('dimensionality_reduction.pkl') |
| RF = joblib.load('random_forest_model.pkl') |
|
|
| |
| 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 |
| ) |
|
|
| |
| st.title("Classify Game Feedback") |
|
|
| st.write("Enter text below to classify:") |
|
|
| |
| user_input = st.text_area("Input Text", "", key="input_text", help="Type your game review here.") |
|
|
| |
| 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: |
| |
| tfidf_input = TF_IDF.transform([user_input]) |
| reduced_input = svd.transform(tfidf_input) |
| |
| |
| 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." |
| |
| |
| 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 |
| ) |
|
|