| import gradio as gr |
| import joblib |
| import pandas as pd |
|
|
| |
| scaler, pca, clf = joblib.load("tennis_model.pkl") |
|
|
| |
| outlook_options = ["Sunny", "Overcast", "Rain"] |
| temp_options = ["Hot", "Mild", "Cool"] |
| humidity_options = ["High", "Normal"] |
| wind_options = ["Weak", "Strong"] |
|
|
| def predict_play(outlook, temp, humidity, wind): |
| |
| data = pd.DataFrame([[outlook, temp, humidity, wind]], |
| columns=["outlook", "temp", "humidity", "wind"]) |
| |
| |
| data_enc = pd.get_dummies(data) |
| |
| |
| for col in scaler.feature_names_in_: |
| if col not in data_enc: |
| data_enc[col] = 0 |
| |
| data_enc = data_enc[scaler.feature_names_in_] |
| |
| |
| X_scaled = scaler.transform(data_enc) |
| X_pca = pca.transform(X_scaled) |
| pred = clf.predict(X_pca)[0] |
| |
| return f"Prediction: {pred}" |
|
|
| |
| with gr.Blocks() as demo: |
| gr.Markdown("# 🎾 Play Tennis Predictor") |
| outlook = gr.Dropdown(outlook_options, label="Outlook") |
| temp = gr.Dropdown(temp_options, label="Temperature") |
| humidity = gr.Dropdown(humidity_options, label="Humidity") |
| wind = gr.Dropdown(wind_options, label="Wind") |
| |
| btn = gr.Button("Predict") |
| output = gr.Textbox(label="Result") |
| |
| btn.click(fn=predict_play, inputs=[outlook, temp, humidity, wind], outputs=output) |
|
|
| demo.launch(server_name="0.0.0.0",server_port=7860,debug=True) |