File size: 4,921 Bytes
857c06a
35239f7
 
8fb8334
 
35239f7
 
 
a1b4f7f
 
857c06a
8fb8334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857c06a
6294029
78add90
 
6294029
03ecc94
78add90
6294029
 
 
 
 
8fb8334
 
 
 
 
 
 
 
 
 
 
 
 
03ecc94
ad90a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ff771
ad90a70
 
 
 
78add90
ad90a70
35239f7
78add90
 
ad90a70
 
 
78add90
 
ad90a70
35239f7
78add90
 
ad90a70
 
6294029
 
 
 
 
 
8fb8334
6294029
 
 
 
ad90a70
 
 
 
03ecc94
 
 
 
 
78add90
 
6294029
03ecc94
 
 
ad90a70
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import gradio as gr
import pandas as pd
import random
from keras.models import load_model
import numpy as np

data = pd.read_pickle("merged_all_table.pkl", compression='bz2')

home_team_id = sorted(data["home_team_long_name"].unique())
away_team_id = sorted(data["away_team_long_name"].unique())

nn_model = load_model('models/nn_model.h5')


def main_process(model, Home_team, Away_team):

    home_temp = data[data["home_team_long_name"] == Home_team]
    home_temp = home_temp[["home_team_overall_score", "home_total_goal", "home_players_avg_overall_rating", "home_players_avg_overall_score", "home_players_avg_ideal_body_rate", "home_total_win", "home_total_loose", "home_total_draw", "league_home_total_win", "league_home_total_loose", "league_home_total_draw"]]
    print("Home Team Data Geathring ✅")

    away_temp = data[data["away_team_long_name"] == Away_team]
    away_temp = away_temp[["away_team_overall_score", "away_total_goal", "away_players_avg_overall_rating", "away_players_avg_overall_score", "away_players_avg_ideal_body_rate", "away_total_win", "away_total_loose", "away_total_draw", "league_away_total_win", "league_away_total_loose", "league_away_total_draw"]]
    print("Away Team Data Geathring ✅")

    table = pd.concat([home_temp.mean(), away_temp.mean()], axis=0)
    table = table[["home_team_overall_score", "away_team_overall_score", "home_total_goal", "away_total_goal", "home_players_avg_overall_rating", "home_players_avg_overall_score", "home_players_avg_ideal_body_rate", "away_players_avg_overall_rating", "away_players_avg_overall_score", "away_players_avg_ideal_body_rate", "home_total_win", "home_total_loose", "home_total_draw", "away_total_win", "away_total_loose", "away_total_draw", "league_home_total_win", "league_home_total_loose", "league_home_total_draw", "league_away_total_win", "league_away_total_loose", "league_away_total_draw"]]
    print("Table Concatination ✅")

    X = table.to_frame().T

    pred = model.predict(X)
    predicted_labels = np.argmax(pred)
    print("Data Prediction ✅")

    print(predicted_labels)

    return predicted_labels


def predict(Home_team, Away_team, Model_name):

    if Home_team == "":
        raise gr.Error("Home Team is required, Please Select The Home Team!")
    
    if Away_team  == "":
        raise gr.Error("Away Team is required, Please Select The Away Team!")
    
    if Model_name  == "":
        raise gr.Error("Model is required, Please Select The Model!")
    
    if Model_name == "Simple Nueral Network Model":
        model = nn_model

    prediction = main_process(model, Home_team, Away_team)

    if prediction == 0:
        return "🥳 Home Team Win 🎉"

    if prediction == 1:
        return "🥳 Away Team Win 🎉"

    if prediction == 2:
        return "😑 Match Draw 😑"


# markup table for markdown
# # Members:
#     | Students Name      | Student ID |
#     |    :---    |    :----:   |
#     | Zeel Karshanbhai Sheladiya      | 500209119       | 
#     | Ravikumar Chandrakantbhai Patel   | 500196861        |
#     | Dharma Teja Reddy Bandreddi   | 500209454        |
#     | Sai Charan Reddy Meda  | 500201602        |
#     | Aditya Babu   | 500209122        |
#     | Sudip Bhattarai   | 500198055        |
#     | NOMAN FAZAL MUKADAM   | 500209115        |
#     | Leela Prasad Kavuri   | 500209550        |
#     | Vamsi Dasari   | 500200775        |

with gr.Blocks() as demo:
    gr.Markdown("""
    [![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/ravi7522/Football-Prediction)
    """)
    with gr.Row():
        gr.Label("⚽️ Football Prediction ⚽️", container=False)

    with gr.Row():
        with gr.Column():

            dd_home_team = gr.Dropdown(
                label="Home Team",
                choices=home_team_id,
                info="Select Your Home Team:",
                multiselect=False,
            )

        with gr.Column(): 
        
            dd_away_team = gr.Dropdown(
                label="Away Team",
                choices=away_team_id,
                info="Select Your Away Team:",
                multiselect=False,
            )

    with gr.Row():

        with gr.Column(): 
        
            dd_model = gr.Dropdown(
                label="Model ( Feature Under Construction 🚧 )",
                choices=["Simple Nueral Network Model"],
                info="Select Your Model:",
                multiselect=False,
            )

    with gr.Row():
        predict_btn = gr.Button(value="Predict")
            
    with gr.Row():
        Answer = gr.Label("👋 Hello, Let us predict the Football Match 💁‍♂️", container=False)

    predict_btn.click(
        predict,
        inputs=[
            dd_home_team,
            dd_away_team,
            dd_model,
        ],
        outputs=[Answer],
    )

demo.launch()