File size: 3,242 Bytes
b72b57c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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}")