Player_Rating / app.py
MAZEN00's picture
Update app.py
00f89c5 verified
import gradio as gr
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
# Download model + columns from your repo
model_path = hf_hub_download(repo_id="MAZEN00/Player", filename="modeel.joblib")
columns_path = hf_hub_download(repo_id="MAZEN00/Player", filename="columns.pkl")
# Load them
model = joblib.load(model_path)
model_columns = joblib.load(columns_path)
# Prediction function
def predict_player(player: dict):
try:
print("Received:", player) # <--- log input
df = pd.DataFrame([player])
df = df[model_columns]
prediction = model.predict(df)
print("Prediction:", prediction) # <--- log output
return float(prediction[0])
except Exception as e:
print("Error:", e) # <--- log errors
return {"error": str(e)}
# Gradio Interface
iface = gr.Interface(
fn=predict_player,
inputs=gr.JSON(label="Player Features"),
outputs=gr.Number(label="Predicted Rating"),
title="⚽ Player Rating Predictor",
description="Enter player features (JSON) to get predicted rating."
)
# Hugging Face Spaces expects launch like this
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)