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()