MAZEN00 commited on
Commit
e820d50
·
verified ·
1 Parent(s): c431b29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
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
- # دالة التوقع بتاخد JSON واحد
14
  def predict_player(player: dict):
15
- df = pd.DataFrame([player])
16
- df = df[model_columns] # ترتيب الأعمدة زي ما اتدرب الموديل
17
- prediction = model.predict(df)
18
- return int(prediction[0])
 
 
 
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
- iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
 
 
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)