test_afnan / app.py
tajuarAkash's picture
Upload 3 files
1a22f40 verified
import gradio as gr
import pandas as pd
import numpy as np
import pickle
# Load the model
with open("model.pkl", "rb") as file:
model = pickle.load(file)
# OPTIONS: These must match exactly what you used in training.
# You can add more options to these lists if needed.
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']
GENRE_OPTIONS = ['Sports', 'Platform', 'Racing', 'Role-Playing', 'Puzzle', 'Misc', 'Shooter', 'Simulation', 'Action', 'Fighting', 'Adventure', 'Strategy']
PUBLISHER_OPTIONS = ['Nintendo', 'Microsoft Game Studios', 'Take-Two Interactive', 'Sony Computer Entertainment', 'Activision', 'Ubisoft', 'Bethesda Softworks', 'Electronic Arts', 'Sega', 'SquareSoft', 'Atari']
def predict_sales(
Platform, Year, Genre, Publisher,
NA_Sales, EU_Sales, JP_Sales, Other_Sales
):
total_sales = NA_Sales + EU_Sales + JP_Sales + Other_Sales
# Create the DataFrame with the exact column names the model expects
input_data = pd.DataFrame([{
"Platform": Platform,
"Year": Year,
"Genre": Genre,
"Publisher": Publisher,
"NA_Sales": NA_Sales,
"EU_Sales": EU_Sales,
"JP_Sales": JP_Sales,
"Other_Sales": Other_Sales,
"Total_Regional_Sales": total_sales,
"NA_ratio": NA_Sales / (total_sales + 1e-6),
"EU_ratio": EU_Sales / (total_sales + 1e-6),
"JP_ratio": JP_Sales / (total_sales + 1e-6),
"Other_ratio": Other_Sales / (total_sales + 1e-6)
}])
# Predict
prediction = model.predict(input_data)[0]
return float(np.clip(prediction, 0, 4))
app = gr.Interface(
fn=predict_sales,
inputs=[
gr.Dropdown(choices=PLATFORM_OPTIONS, label="Platform"), # Safer than Textbox
gr.Number(label="Year", value=2010),
gr.Dropdown(choices=GENRE_OPTIONS, label="Genre"), # Safer than Textbox
gr.Dropdown(choices=PUBLISHER_OPTIONS, label="Publisher"), # Safer than Textbox
gr.Number(label="NA_Sales"),
gr.Number(label="EU_Sales"),
gr.Number(label="JP_Sales"),
gr.Number(label="Other_Sales"),
],
outputs=gr.Number(label="Predicted Global Sales (millions)"),
title="Video Game Global Sales Prediction",
description="Enter game details to predict Global Sales (millions)."
)
app.launch()