Spaces:
Sleeping
Sleeping
| 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; /* Adjust title font size */ | |
| 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; /* Adjust input text font size */ | |
| } | |
| /* Style for the button */ | |
| .stButton>button { | |
| background-color: #4CAF50; /* Green */ | |
| color: white; | |
| font-size: 1.2em; /* Adjust button font size */ | |
| 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: rgba(0, 0, 255, 0.9); /* Semi-transparent white */ | |
| color: #000000; /* Black */ | |
| font-size: 1.5em; /* Adjust output text font size */ | |
| padding: 15px; | |
| border-radius: 10px; | |
| text-align: center; | |
| margin-top: 20px; | |
| } | |
| </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 | |
| st.success(f"The review is **{sentiment}** with a confidence score of {confidence:.2f}%.") | |
| st.info(f"*Insight:* {insight}") | |