File size: 1,226 Bytes
e546f20
94947fe
1477609
6f862c8
804ff01
e820d50
6f862c8
 
 
e820d50
6f862c8
1477609
e546f20
e820d50
1477609
e820d50
00f89c5
e820d50
00f89c5
e820d50
00f89c5
 
e820d50
00f89c5
e820d50
e546f20
00f89c5
e820d50
1477609
 
 
 
e820d50
 
1477609
804ff01
e820d50
 
 
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
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)