tmarks-adobe commited on
Commit
dc5b036
1 Parent(s): 7ee1e8d

Upload 4 files

Browse files
Files changed (3) hide show
  1. app.py +144 -0
  2. cfb-prediction.pkl +3 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cfbd
3
+ import numpy as np
4
+ import pandas as pd
5
+ from fastai.tabular import *
6
+ from fastai.tabular.all import *
7
+
8
+ configuration = cfbd.Configuration()
9
+ configuration.api_key["Authorization"] = "be81N7cB5mpl4z+BdHBuD5wUACNkh5YSAhO8uaC3tKCRAgC9WMhJjoHrO3Qx3TFp"
10
+ configuration.api_key_prefix["Authorization"] = "Bearer"
11
+ api_config = cfbd.ApiClient(configuration)
12
+ teams_api = cfbd.TeamsApi(api_config)
13
+ ratings_api = cfbd.RatingsApi(api_config)
14
+ games_api = cfbd.GamesApi(api_config)
15
+ betting_api = cfbd.BettingApi(api_config)
16
+
17
+
18
+ def predict(game_details):
19
+ learn = load_learner("cfb-prediction.pkl")
20
+
21
+ pdf = pd.DataFrame([game_details])
22
+ dl = learn.dls.test_dl(pdf)
23
+ pdf["predicted"] = learn.get_preds(dl=dl)[0].numpy()
24
+ pdf['margin'] = abs(game_details['home_points'] - game_details['away_points'])
25
+
26
+ return pdf[['home_team','away_team','home_points','away_points','spread','margin','predicted']]
27
+
28
+
29
+ # def home_team_change(x):
30
+ # ratings = ratings_api.get_elo_ratings(team=x, year=2023)
31
+ # team_detail = ratings[0]
32
+ # return "Conference: " + team_detail.conference + ", ELO Rating: " + str(team_detail.elo)
33
+
34
+
35
+ def home_team_change(team, year):
36
+ games = games_api.get_games(team=team, year=year)
37
+ names = []
38
+ for game in games:
39
+ if game.home_team == team:
40
+ names.append(game.away_team)
41
+ else:
42
+ names.append(game.home_team)
43
+
44
+ return gr.update(choices=names, value=None)
45
+
46
+
47
+ def get_game_details(year, target, opponent):
48
+ games = games_api.get_games(team=target, year=year)
49
+ the_game = null
50
+
51
+ for game in games:
52
+ if game.home_team == opponent or game.away_team == opponent:
53
+ the_game = dict(
54
+ id=game.id,
55
+ year=game.season,
56
+ week=game.week,
57
+ neutral_site=game.neutral_site,
58
+ home_team=game.home_team,
59
+ home_conference=game.home_conference,
60
+ home_points=game.home_points,
61
+ home_elo=game.home_pregame_elo,
62
+ away_team=game.away_team,
63
+ away_conference=game.away_conference,
64
+ away_points=game.away_points,
65
+ away_elo=game.away_pregame_elo,
66
+ )
67
+ break
68
+
69
+ spread = betting_api.get_lines(game_id=the_game['id'],year=year)
70
+
71
+ the_game['spread'] = spread[0].lines[0].spread
72
+
73
+ return the_game
74
+
75
+ def lookup_teams(teams_api):
76
+ team_names = []
77
+ teams = teams_api.get_fbs_teams()
78
+ for team in teams:
79
+ team_names.append(team.school)
80
+
81
+ return team_names
82
+
83
+
84
+ def update_target(x):
85
+ print(x)
86
+
87
+
88
+ teams = lookup_teams(teams_api)
89
+
90
+ with gr.Blocks() as app:
91
+ with gr.Row():
92
+ with gr.Column(scale=1):
93
+ yearDd = gr.Dropdown(
94
+ [2023, 2022, 2021, 2020, 2019, 2018, 2017], label="Year"
95
+ )
96
+ with gr.Row():
97
+ with gr.Column(scale=1):
98
+ ddTeams1 = gr.Dropdown(choices=teams, label="Target Team")
99
+ with gr.Column(scale=1):
100
+ oponents = gr.Dropdown(choices=[], label="Opponents", interactive=True)
101
+ # with gr.Column(scale=1):
102
+ # ddTeams2 = gr.Dropdown(choices=teams, label="Away Team")
103
+ # label2 = (gr.Label(num_top_classes=4, label="Away Team Details"))
104
+ # ddTeams2.select(home_team_change, inputs=ddTeams2, outputs=[label2])
105
+ with gr.Row():
106
+ game_details = gr.JSON({})
107
+ with gr.Row():
108
+ submit = gr.Button("Predict")
109
+ with gr.Row():
110
+ data_table = gr.Dataframe(
111
+ headers=["Home Team", "Away Team", "Home Points", "Away Points", "Consensus Spread", "Margin", "Predicted Spread"],
112
+ datatype=["str", "str", "number", "number", "number", "number", "number"],
113
+ row_count=1,
114
+ col_count=(7, "dynamic")
115
+ )
116
+
117
+ ddTeams1.select(home_team_change, inputs=[ddTeams1, yearDd], outputs=[oponents])
118
+ oponents.select(
119
+ get_game_details,
120
+ inputs=[yearDd, ddTeams1, oponents],
121
+ outputs=[game_details]
122
+ )
123
+ submit.click(
124
+ predict, inputs=[game_details], outputs=[data_table]
125
+ )
126
+ app.launch()
127
+
128
+
129
+ # import gradio as gr
130
+
131
+ # languages = ['spanish', 'english']
132
+ # homeworks = {'spanish': ['hola', 'bien', 'gracias'], 'english': ['hello', 'good', 'thank you']}
133
+
134
+ # def rs_change(rs):
135
+ # return gr.update(choices=homeworks[rs], value=None)
136
+
137
+ # with gr.Blocks() as app:
138
+
139
+ # rs = gr.Dropdown(choices=languages, value='english')
140
+ # rs_hw = gr.Dropdown(choices=homeworks['english'], interactive=True)
141
+
142
+ # rs.change(fn=rs_change, inputs=[rs], outputs=[rs_hw])
143
+
144
+ # app.launch()
cfb-prediction.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a6f950de0b7a1cddd6a7dcd30e469b1a107730f1780b7733597c51c0d08d9f8
3
+ size 136375
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ cfbd
2
+ fastai
3
+ pandas