Spaces:
Sleeping
Sleeping
File size: 2,834 Bytes
2347e90 2a72f29 2347e90 9d3d041 2347e90 2f70a75 2a72f29 02fa7db 2a72f29 f2f82e3 02fa7db 2a72f29 2347e90 2f70a75 2347e90 | 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import gradio as gr
import xgboost as xgb
import pandas as pd
import numpy as np
# Load the trained XGBoost model
model = xgb.Booster()
model.load_model("xgboost_model.json") # Update with your model path
# Define the function to predict auction price
def predict_auction_price(matches, ipl_runs, strike_rate, average, budget, team_batsman,
team_fast_bowler, team_spin_bowler, team_fast_bowling_allrounder,
team_spin_bowling_allrounder, team_wk, team_away_player, age,
is_away, player_type, wickets, economy, is_fast_bowler, bowl_strike_rate):
# Create a DataFrame with the correct column names (matching model's training data)
input_data = pd.DataFrame([[matches, ipl_runs, strike_rate, average, budget, team_batsman,
team_fast_bowler, team_spin_bowler, team_fast_bowling_allrounder,
team_spin_bowling_allrounder, team_wk, team_away_player, age, is_away,
player_type, wickets, economy, is_fast_bowler, bowl_strike_rate]],
columns=['matches', 'Ipl runs', 'strike rate', 'average', 'budget', 'team batsman',
'team fast bowler', 'team spin bowler', 'team fast bowling allrounder',
'team spin bowling alrounder', 'team wk', 'team away player', 'age',
'away', 'type', 'wickets', 'economy', 'is fastbowler', 'bowl strike rate'])
# Convert to DMatrix for XGBoost
dmatrix = xgb.DMatrix(input_data)
# Predict the auction price
prediction = model.predict(dmatrix)
return prediction[0] # Return the predicted auction price
# Create Gradio interface
interface = gr.Interface(
fn=predict_auction_price,
inputs=[
gr.Number(label="Matches"),
gr.Number(label="IPL Runs"),
gr.Number(label="Strike Rate"),
gr.Number(label="Average"),
gr.Number(label="Budget"),
gr.Number(label="Team Batsman"),
gr.Number(label="Team Fast Bowler"),
gr.Number(label="Team Spin Bowler"),
gr.Number(label="Team Fast Bowling Allrounder"),
gr.Number(label="Team Spin Bowling Allrounder"),
gr.Number(label="Team WK"),
gr.Number(label="Team Away Player"),
gr.Number(label="Age"),
gr.Number(label="Is Away", value=0),
gr.Number(label="Player Type", value=1), # Default value is batsman
gr.Number(label="Wickets"),
gr.Number(label="Economy"),
gr.Number(label="Is Fast Bowler", value=0),
gr.Number(label="Bowl Strike Rate")
],
outputs=gr.Number(label="Predicted Auction Price")
)
# Launch the Gradio interface
interface.launch()
|