Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,25 +3,33 @@ import pandas as pd
|
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
-
#
|
| 7 |
model_path = hf_hub_download(repo_id="MAZEN00/Player", filename="modeel.joblib")
|
| 8 |
columns_path = hf_hub_download(repo_id="MAZEN00/Player", filename="columns.pkl")
|
| 9 |
|
|
|
|
| 10 |
model = joblib.load(model_path)
|
| 11 |
model_columns = joblib.load(columns_path)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
def predict_player(player: dict):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# Gradio
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=predict_player,
|
| 23 |
inputs=gr.JSON(label="Player Features"),
|
| 24 |
outputs=gr.Number(label="Predicted Rating"),
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
+
# Download model + columns from your repo
|
| 7 |
model_path = hf_hub_download(repo_id="MAZEN00/Player", filename="modeel.joblib")
|
| 8 |
columns_path = hf_hub_download(repo_id="MAZEN00/Player", filename="columns.pkl")
|
| 9 |
|
| 10 |
+
# Load them
|
| 11 |
model = joblib.load(model_path)
|
| 12 |
model_columns = joblib.load(columns_path)
|
| 13 |
|
| 14 |
+
# Prediction function
|
| 15 |
def predict_player(player: dict):
|
| 16 |
+
try:
|
| 17 |
+
df = pd.DataFrame([player])
|
| 18 |
+
df = df[model_columns] # align with training columns
|
| 19 |
+
prediction = model.predict(df)
|
| 20 |
+
return float(prediction[0]) # float is safer than int for regression
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return {"error": str(e)}
|
| 23 |
|
| 24 |
+
# Gradio Interface
|
| 25 |
iface = gr.Interface(
|
| 26 |
fn=predict_player,
|
| 27 |
inputs=gr.JSON(label="Player Features"),
|
| 28 |
outputs=gr.Number(label="Predicted Rating"),
|
| 29 |
+
title="⚽ Player Rating Predictor",
|
| 30 |
+
description="Enter player features (JSON) to get predicted rating."
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Hugging Face Spaces expects launch like this
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|