Spaces:
Sleeping
Sleeping
File size: 2,266 Bytes
f374077 14529a9 f374077 14529a9 | 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 | import streamlit as st
import joblib
import pandas as pd
import numpy as np
MODEL_PATH = 'src/vgsales_prediction.joblib'
FEATURES = ["Rank", "NA_Sales", "EU_Sales", "JP_Sales", "Other_Sales"]
@st.cache_resource
def load_linear_model():
try:
model = joblib.load(MODEL_PATH)
return model
except Exception as e:
st.error(f"Error loading the Linear Regression model. Ensure '{MODEL_PATH}' is uploaded. Error: {e}")
return None
def predict_sales(model, input_data):
input_df = pd.DataFrame([input_data])[FEATURES]
prediction = model.predict(input_df)
return float(prediction[0])
# --- Streamlit Interface ---
st.set_page_config(page_title="Game Sales Predictor", layout="centered")
st.title("🎮 Global Video Game Sales Prediction")
st.markdown("Enter regional sales figures (in Millions) and Rank to predict total Global Sales.")
model = load_linear_model()
if model is not None:
st.sidebar.header("Sales Input (in Millions)")
rank = st.sidebar.number_input("Game Rank:", min_value=1, value=1000)
na_sales = st.sidebar.number_input("North America Sales (NA_Sales):", min_value=0.0, value=0.5, step=0.01)
eu_sales = st.sidebar.number_input("Europe Sales (EU_Sales):", min_value=0.0, value=0.25, step=0.01)
jp_sales = st.sidebar.number_input("Japan Sales (JP_Sales):", min_value=0.0, value=0.1, step=0.01)
other_sales = st.sidebar.number_input("Other Sales (Other_Sales):", min_value=0.0, value=0.05, step=0.01)
input_data = {
"Rank": rank,
"NA_Sales": na_sales,
"EU_Sales": eu_sales,
"JP_Sales": jp_sales,
"Other_Sales": other_sales
}
st.subheader("Regional Sales Input (Millions):")
st.dataframe(pd.DataFrame([input_data]), hide_index=True)
if st.button("Predict Global Sales"):
with st.spinner('Calculating prediction...'):
predicted_global_sales = predict_sales(model, input_data)
st.success("Prediction Successful!")
st.markdown("### Predicted Global Sales:")
st.markdown(f"**{predicted_global_sales:,.2f} Million**")
st.info("Note: This simple linear model uses Rank and regional sales to predict the total.") |