Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,25 +2,16 @@ import streamlit as st
|
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
import tensorflow as tf
|
| 5 |
-
from sklearn.preprocessing import
|
| 6 |
import joblib
|
| 7 |
|
| 8 |
# Load the trained model
|
| 9 |
model = tf.keras.models.load_model('trained_game_price_model.h5')
|
| 10 |
|
| 11 |
# Function to preprocess the input data
|
| 12 |
-
def preprocess_input(data,
|
| 13 |
# Convert input into DataFrame for processing
|
| 14 |
-
input_data = pd.DataFrame([data]
|
| 15 |
-
|
| 16 |
-
# Apply OneHotEncoder for categorical features
|
| 17 |
-
input_data_transformed = ohe.transform(input_data[['genre', 'targetPlatform']])
|
| 18 |
-
|
| 19 |
-
# Ensure numerical features are 2D
|
| 20 |
-
numerical_features = input_data[['gamePlays', 'competitorPricing', 'currencyFluctuations']].values.reshape(1, -1)
|
| 21 |
-
|
| 22 |
-
# Merge with numerical features
|
| 23 |
-
input_data = np.hstack((input_data_transformed.toarray(), numerical_features))
|
| 24 |
|
| 25 |
# Scale the features
|
| 26 |
input_data_scaled = scaler.transform(input_data)
|
|
@@ -30,56 +21,84 @@ def preprocess_input(data, ohe, scaler):
|
|
| 30 |
# Function to make a prediction
|
| 31 |
def make_prediction(input_data):
|
| 32 |
# Preprocess the data for the model
|
| 33 |
-
input_data_scaled = preprocess_input(input_data,
|
| 34 |
|
| 35 |
# Make prediction
|
| 36 |
prediction = model.predict(input_data_scaled)
|
| 37 |
|
| 38 |
return prediction[0][0]
|
| 39 |
|
| 40 |
-
# Load pre-trained
|
| 41 |
-
|
| 42 |
-
scaler = joblib.load('scaler.pkl') # Load the StandardScaler
|
| 43 |
|
| 44 |
# Streamlit application
|
| 45 |
-
st.title("Game Price Prediction App")
|
| 46 |
|
| 47 |
st.write("""
|
| 48 |
-
### Enter the game details below to predict its price.
|
|
|
|
| 49 |
""")
|
| 50 |
|
| 51 |
# Game details form
|
| 52 |
with st.form("game_details_form"):
|
| 53 |
genre = st.selectbox('Genre', ['Action', 'RPG', 'Puzzle', 'Adventure', 'Simulation', 'Strategy', 'Horror', 'Fighting', 'Sports', 'Racing', 'Casual', 'MOBA', 'Sandbox'])
|
| 54 |
target_platform = st.selectbox('Platform', ['PC', 'PlayStation', 'Xbox', 'Mobile', 'Switch', 'Nintendo 3DS', 'VR', 'Web'])
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# Submit button
|
| 60 |
-
submitted = st.form_submit_button("Predict Price")
|
| 61 |
|
| 62 |
# Prediction logic
|
| 63 |
if submitted:
|
| 64 |
# Prepare input data
|
| 65 |
input_data = {
|
| 66 |
'genre': genre,
|
| 67 |
-
'
|
| 68 |
-
'
|
| 69 |
-
'
|
| 70 |
-
'
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
# Make prediction
|
| 74 |
predicted_price = make_prediction(input_data)
|
| 75 |
|
| 76 |
# Display results
|
| 77 |
-
st.write(f"### Predicted
|
| 78 |
|
| 79 |
# Show the input details for reference
|
| 80 |
st.write("#### Input Details:")
|
| 81 |
st.write(f"- **Genre**: {genre}")
|
| 82 |
st.write(f"- **Platform**: {target_platform}")
|
| 83 |
-
st.write(f"- **
|
| 84 |
-
st.write(f"- **
|
| 85 |
-
st.write(f"- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
import tensorflow as tf
|
| 5 |
+
from sklearn.preprocessing import StandardScaler
|
| 6 |
import joblib
|
| 7 |
|
| 8 |
# Load the trained model
|
| 9 |
model = tf.keras.models.load_model('trained_game_price_model.h5')
|
| 10 |
|
| 11 |
# Function to preprocess the input data
|
| 12 |
+
def preprocess_input(data, scaler):
|
| 13 |
# Convert input into DataFrame for processing
|
| 14 |
+
input_data = pd.DataFrame([data])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Scale the features
|
| 17 |
input_data_scaled = scaler.transform(input_data)
|
|
|
|
| 21 |
# Function to make a prediction
|
| 22 |
def make_prediction(input_data):
|
| 23 |
# Preprocess the data for the model
|
| 24 |
+
input_data_scaled = preprocess_input(input_data, scaler)
|
| 25 |
|
| 26 |
# Make prediction
|
| 27 |
prediction = model.predict(input_data_scaled)
|
| 28 |
|
| 29 |
return prediction[0][0]
|
| 30 |
|
| 31 |
+
# Load pre-trained StandardScaler
|
| 32 |
+
scaler = joblib.load('scaler.pkl')
|
|
|
|
| 33 |
|
| 34 |
# Streamlit application
|
| 35 |
+
st.title("Dynamic Game Price Prediction App")
|
| 36 |
|
| 37 |
st.write("""
|
| 38 |
+
### Enter the game details below to predict its optimal price.
|
| 39 |
+
This model considers actual sales data and market trends for more accurate pricing.
|
| 40 |
""")
|
| 41 |
|
| 42 |
# Game details form
|
| 43 |
with st.form("game_details_form"):
|
| 44 |
genre = st.selectbox('Genre', ['Action', 'RPG', 'Puzzle', 'Adventure', 'Simulation', 'Strategy', 'Horror', 'Fighting', 'Sports', 'Racing', 'Casual', 'MOBA', 'Sandbox'])
|
| 45 |
target_platform = st.selectbox('Platform', ['PC', 'PlayStation', 'Xbox', 'Mobile', 'Switch', 'Nintendo 3DS', 'VR', 'Web'])
|
| 46 |
+
total_sales = st.number_input('Total Sales (units)', min_value=0, value=10000)
|
| 47 |
+
initial_price = st.number_input('Initial Price Offering ($)', min_value=0.0, value=29.99, format="%.2f")
|
| 48 |
+
revenue = total_sales * initial_price
|
| 49 |
+
st.write(f"Current Revenue: ${revenue:.2f}")
|
| 50 |
+
|
| 51 |
+
avg_market_price = st.number_input('Average Market Price for Similar Games ($)', min_value=0.0, value=24.99, format="%.2f")
|
| 52 |
+
market_saturation = st.slider('Market Saturation (0-100%)', min_value=0, max_value=100, value=50)
|
| 53 |
+
user_rating = st.slider('User Rating (0-5 stars)', min_value=0.0, max_value=5.0, value=4.0, step=0.1)
|
| 54 |
+
|
| 55 |
# Submit button
|
| 56 |
+
submitted = st.form_submit_button("Predict Optimal Price")
|
| 57 |
|
| 58 |
# Prediction logic
|
| 59 |
if submitted:
|
| 60 |
# Prepare input data
|
| 61 |
input_data = {
|
| 62 |
'genre': genre,
|
| 63 |
+
'target_platform': target_platform,
|
| 64 |
+
'total_sales': total_sales,
|
| 65 |
+
'initial_price': initial_price,
|
| 66 |
+
'revenue': revenue,
|
| 67 |
+
'avg_market_price': avg_market_price,
|
| 68 |
+
'market_saturation': market_saturation / 100, # Convert to 0-1 scale
|
| 69 |
+
'user_rating': user_rating
|
| 70 |
}
|
| 71 |
|
| 72 |
# Make prediction
|
| 73 |
predicted_price = make_prediction(input_data)
|
| 74 |
|
| 75 |
# Display results
|
| 76 |
+
st.write(f"### Predicted Optimal Price: ${predicted_price:.2f}")
|
| 77 |
|
| 78 |
# Show the input details for reference
|
| 79 |
st.write("#### Input Details:")
|
| 80 |
st.write(f"- **Genre**: {genre}")
|
| 81 |
st.write(f"- **Platform**: {target_platform}")
|
| 82 |
+
st.write(f"- **Total Sales**: {total_sales}")
|
| 83 |
+
st.write(f"- **Initial Price**: ${initial_price:.2f}")
|
| 84 |
+
st.write(f"- **Current Revenue**: ${revenue:.2f}")
|
| 85 |
+
st.write(f"- **Avg. Market Price**: ${avg_market_price:.2f}")
|
| 86 |
+
st.write(f"- **Market Saturation**: {market_saturation}%")
|
| 87 |
+
st.write(f"- **User Rating**: {user_rating} stars")
|
| 88 |
+
|
| 89 |
+
# Provide some insights
|
| 90 |
+
price_difference = predicted_price - initial_price
|
| 91 |
+
if abs(price_difference) < 1:
|
| 92 |
+
st.write("The predicted optimal price is close to your initial price. Your pricing strategy seems to be aligned with the market.")
|
| 93 |
+
elif price_difference > 0:
|
| 94 |
+
st.write(f"The model suggests increasing your price by ${price_difference:.2f}. This might help maximize revenue, but consider the potential impact on sales volume.")
|
| 95 |
+
else:
|
| 96 |
+
st.write(f"The model suggests decreasing your price by ${-price_difference:.2f}. This might help increase sales volume and overall revenue.")
|
| 97 |
+
|
| 98 |
+
st.write("Remember, this is a prediction based on the provided data. Always consider other factors like marketing strategies, seasonal trends, and your specific game's unique value proposition when making pricing decisions.")
|
| 99 |
+
|
| 100 |
+
# Add a note about the dynamic nature of the marketplace
|
| 101 |
+
st.write("""
|
| 102 |
+
#### Note on Marketplace Dynamics
|
| 103 |
+
This prediction model takes into account current market trends and your game's performance. As the marketplace is dynamic, it's recommended to periodically reassess your pricing strategy using updated sales data and market information.
|
| 104 |
+
""")
|