Spaces:
Runtime error
Runtime error
tmarks-adobe
commited on
Commit
•
a540d37
1
Parent(s):
36de98d
Upload 4 files
Browse files- app.py +138 -0
- requirements.txt +3 -0
- talking_tech_neural_net.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
all_teams = teams_api.get_teams()
|
18 |
+
|
19 |
+
|
20 |
+
def greet(name):
|
21 |
+
return "Hello " + name + "!!"
|
22 |
+
|
23 |
+
|
24 |
+
def normalize_teams():
|
25 |
+
teams = teams_api.get_fbs_teams()
|
26 |
+
team_names = []
|
27 |
+
for team in teams:
|
28 |
+
team_names.append(team.school)
|
29 |
+
|
30 |
+
return team_names
|
31 |
+
|
32 |
+
|
33 |
+
def home_team(year, team):
|
34 |
+
elo = find_most_recent_elo(year, team)
|
35 |
+
team_details = filter_team(team)
|
36 |
+
|
37 |
+
return dict(
|
38 |
+
team=team,
|
39 |
+
conference=team_details.conference,
|
40 |
+
elo=elo
|
41 |
+
)
|
42 |
+
|
43 |
+
|
44 |
+
def away_team(year, team):
|
45 |
+
elo = find_most_recent_elo(year, team)
|
46 |
+
team_details = filter_team(team)
|
47 |
+
|
48 |
+
return dict(
|
49 |
+
team=team,
|
50 |
+
conference=team_details.conference,
|
51 |
+
elo=elo
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
+
def filter_team(team_name):
|
56 |
+
for team in all_teams:
|
57 |
+
if team.school == team_name:
|
58 |
+
return team
|
59 |
+
|
60 |
+
|
61 |
+
def enable_teams():
|
62 |
+
return gr.update(choices=teams, value=None, interactive=True), gr.update(choices=teams, value=None,
|
63 |
+
interactive=True)
|
64 |
+
|
65 |
+
|
66 |
+
def predict(hteam, ateam):
|
67 |
+
learn = load_learner('talking_tech_neural_net.pkl')
|
68 |
+
|
69 |
+
game_details = dict(
|
70 |
+
neutral_site=False,
|
71 |
+
home_team=hteam['team'],
|
72 |
+
home_conference=hteam['conference'],
|
73 |
+
home_elo=hteam['elo'],
|
74 |
+
away_team=ateam['team'],
|
75 |
+
away_conference=ateam['conference'],
|
76 |
+
away_elo=ateam['elo'],
|
77 |
+
)
|
78 |
+
|
79 |
+
pdf = pd.DataFrame([game_details])
|
80 |
+
dl = learn.dls.test_dl(pdf)
|
81 |
+
pdf["predicted"] = learn.get_preds(dl=dl)[0].numpy()
|
82 |
+
|
83 |
+
return pdf
|
84 |
+
|
85 |
+
|
86 |
+
def find_most_recent_elo(year, team):
|
87 |
+
games = games_api.get_games(team=team, year=year)
|
88 |
+
reversed = sorted(games, key=lambda x: x.week, reverse=True)
|
89 |
+
|
90 |
+
elo = null
|
91 |
+
if reversed[0].home_team == team:
|
92 |
+
if reversed[0].home_postgame_elo != None:
|
93 |
+
elo = reversed[0].home_postgame_elo
|
94 |
+
else:
|
95 |
+
elo = reversed[0].home_pregame_elo
|
96 |
+
else:
|
97 |
+
if reversed[0].away_postgame_elo != None:
|
98 |
+
elo = reversed[0].away_postgame_elo
|
99 |
+
else:
|
100 |
+
elo = reversed[0].away_pregame_elo
|
101 |
+
|
102 |
+
return elo
|
103 |
+
|
104 |
+
|
105 |
+
teams = normalize_teams()
|
106 |
+
|
107 |
+
with gr.Blocks() as app:
|
108 |
+
with gr.Row():
|
109 |
+
with gr.Column(scale=1):
|
110 |
+
year = gr.Dropdown([2023, 2022, 2021, 2020, 2019, 2018, 2017], label="Year")
|
111 |
+
with gr.Row():
|
112 |
+
with gr.Column(scale=1):
|
113 |
+
team_one = gr.Dropdown(choices=teams, label="Home Team", interactive=False)
|
114 |
+
with gr.Column(scale=1):
|
115 |
+
team_two = gr.Dropdown(choices=teams, label="Away Team", interactive=False)
|
116 |
+
with gr.Row():
|
117 |
+
with gr.Column(scale=1):
|
118 |
+
team_one_label = gr.JSON(label='Home Team Details')
|
119 |
+
with gr.Column(scale=1):
|
120 |
+
team_two_label = gr.JSON(label='Away Team Details')
|
121 |
+
with gr.Row():
|
122 |
+
predict_btn = gr.Button('Predict Spread')
|
123 |
+
with gr.Row():
|
124 |
+
data_table = gr.Dataframe(
|
125 |
+
label="Prediction Details",
|
126 |
+
headers=["Neutral Site", "Home Team", "Home Conference", "Home ELO", "Home Team", "Home Conference",
|
127 |
+
"Home ELO", "Predicted Spread"],
|
128 |
+
datatype=["bool", "str", "str", "number", "str", "str", "number", "number"],
|
129 |
+
row_count=1,
|
130 |
+
col_count=(8, "dynamic")
|
131 |
+
)
|
132 |
+
|
133 |
+
year.select(enable_teams, outputs=[team_one, team_two])
|
134 |
+
team_one.select(home_team, inputs=[year, team_one], outputs=[team_one_label])
|
135 |
+
team_two.select(away_team, inputs=[year, team_two], outputs=[team_two_label])
|
136 |
+
predict_btn.click(predict, inputs=[team_one_label, team_two_label], outputs=[data_table])
|
137 |
+
|
138 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
cfbd
|
2 |
+
fastai
|
3 |
+
pandas
|
talking_tech_neural_net.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3df4b8e982e3aa3501401a01ebd7bb178009473c8516bd4bc8cf3c9144b1b18f
|
3 |
+
size 137060
|