Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +60 -0
- model.pkl +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
# Load the model
|
| 7 |
+
with open("model.pkl", "rb") as file:
|
| 8 |
+
model = pickle.load(file)
|
| 9 |
+
|
| 10 |
+
# OPTIONS: These must match exactly what you used in training.
|
| 11 |
+
# You can add more options to these lists if needed.
|
| 12 |
+
PLATFORM_OPTIONS = ['Wii', 'NES', 'GB', 'DS', 'X360', 'PS3', 'PS2', 'SNES', 'GBA', '3DS', 'PS4', 'N64', 'PS5', 'XB', 'PC', '2600', 'PSP', 'XOne', 'GC', 'WiiU', 'GEN', 'DC', 'PSV', 'SAT', 'SCD', 'WS', 'NG', 'TG16', '3DO', 'GG', 'PCFX']
|
| 13 |
+
GENRE_OPTIONS = ['Sports', 'Platform', 'Racing', 'Role-Playing', 'Puzzle', 'Misc', 'Shooter', 'Simulation', 'Action', 'Fighting', 'Adventure', 'Strategy']
|
| 14 |
+
PUBLISHER_OPTIONS = ['Nintendo', 'Microsoft Game Studios', 'Take-Two Interactive', 'Sony Computer Entertainment', 'Activision', 'Ubisoft', 'Bethesda Softworks', 'Electronic Arts', 'Sega', 'SquareSoft', 'Atari']
|
| 15 |
+
|
| 16 |
+
def predict_sales(
|
| 17 |
+
Platform, Year, Genre, Publisher,
|
| 18 |
+
NA_Sales, EU_Sales, JP_Sales, Other_Sales
|
| 19 |
+
):
|
| 20 |
+
total_sales = NA_Sales + EU_Sales + JP_Sales + Other_Sales
|
| 21 |
+
|
| 22 |
+
# Create the DataFrame with the exact column names the model expects
|
| 23 |
+
input_data = pd.DataFrame([{
|
| 24 |
+
"Platform": Platform,
|
| 25 |
+
"Year": Year,
|
| 26 |
+
"Genre": Genre,
|
| 27 |
+
"Publisher": Publisher,
|
| 28 |
+
"NA_Sales": NA_Sales,
|
| 29 |
+
"EU_Sales": EU_Sales,
|
| 30 |
+
"JP_Sales": JP_Sales,
|
| 31 |
+
"Other_Sales": Other_Sales,
|
| 32 |
+
"Total_Regional_Sales": total_sales,
|
| 33 |
+
"NA_ratio": NA_Sales / (total_sales + 1e-6),
|
| 34 |
+
"EU_ratio": EU_Sales / (total_sales + 1e-6),
|
| 35 |
+
"JP_ratio": JP_Sales / (total_sales + 1e-6),
|
| 36 |
+
"Other_ratio": Other_Sales / (total_sales + 1e-6)
|
| 37 |
+
}])
|
| 38 |
+
|
| 39 |
+
# Predict
|
| 40 |
+
prediction = model.predict(input_data)[0]
|
| 41 |
+
return float(np.clip(prediction, 0, 4))
|
| 42 |
+
|
| 43 |
+
app = gr.Interface(
|
| 44 |
+
fn=predict_sales,
|
| 45 |
+
inputs=[
|
| 46 |
+
gr.Dropdown(choices=PLATFORM_OPTIONS, label="Platform"), # Safer than Textbox
|
| 47 |
+
gr.Number(label="Year", value=2010),
|
| 48 |
+
gr.Dropdown(choices=GENRE_OPTIONS, label="Genre"), # Safer than Textbox
|
| 49 |
+
gr.Dropdown(choices=PUBLISHER_OPTIONS, label="Publisher"), # Safer than Textbox
|
| 50 |
+
gr.Number(label="NA_Sales"),
|
| 51 |
+
gr.Number(label="EU_Sales"),
|
| 52 |
+
gr.Number(label="JP_Sales"),
|
| 53 |
+
gr.Number(label="Other_Sales"),
|
| 54 |
+
],
|
| 55 |
+
outputs=gr.Number(label="Predicted Global Sales (millions)"),
|
| 56 |
+
title="Video Game Global Sales Prediction",
|
| 57 |
+
description="Enter game details to predict Global Sales (millions)."
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
app.launch()
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e8f7e5400e5eda44b42cc03c9cd9a0235db18d5e07d45d34f7c93e395db7c65d
|
| 3 |
+
size 10168224
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
scikit-learn
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
gradio
|