Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import pickle
|
5 |
+
import xgboost as xgb
|
6 |
+
|
7 |
+
def predict(team, inning, venue, hits, errors, leftonbase, runs):
|
8 |
+
|
9 |
+
data = [team, inning, venue, hits, errors, runs, leftonbase]
|
10 |
+
df = pd.DataFrame([data], columns=["Team_Name", "Inning", "Home/Away", "Hits", "Errors", "Runs", "Leftonbase"])
|
11 |
+
|
12 |
+
xgb_model = xgb.XGBRegressor()
|
13 |
+
xgb_model.load_model('xgbr3_model3.json')
|
14 |
+
|
15 |
+
with open('label_encoder_teams3.pkl', 'rb') as f:
|
16 |
+
label_encoder = pickle.load(f)
|
17 |
+
|
18 |
+
df['Team_Name'] = label_encoder.fit_transform(df['Team_Name'])
|
19 |
+
|
20 |
+
home_away_status = {'Home': 0, 'Away': 1}
|
21 |
+
df['Home/Away'] = df['Home/Away'].map(home_away_status)
|
22 |
+
score = xgb_model.predict(df)
|
23 |
+
return np.round(score[0],1)
|
24 |
+
|
25 |
+
team_names = ["Arizona Diamondbacks",
|
26 |
+
"Atlanta Braves",
|
27 |
+
"Baltimore Orioles",
|
28 |
+
"Boston Red Sox",
|
29 |
+
"Chicago Cubs",
|
30 |
+
"Chicago White Sox",
|
31 |
+
"Cincinnati Reds",
|
32 |
+
"Cleveland Guardians",
|
33 |
+
"Colorado Rockies",
|
34 |
+
"Detroit Tigers",
|
35 |
+
"Houston Astros",
|
36 |
+
"Kansas City Royals",
|
37 |
+
"Los Angeles Angels",
|
38 |
+
"Los Angeles Dodgers",
|
39 |
+
"Miami Marlins",
|
40 |
+
"Milwaukee Brewers",
|
41 |
+
"Minnesota Twins",
|
42 |
+
"New York Mets",
|
43 |
+
"New York Yankees",
|
44 |
+
"Oakland Athletics",
|
45 |
+
"Philadelphia Phillies",
|
46 |
+
"Pittsburgh Pirates",
|
47 |
+
"San Diego Padres",
|
48 |
+
"San Francisco Giants",
|
49 |
+
"Seattle Mariners",
|
50 |
+
"St. Louis Cardinals",
|
51 |
+
"Tampa Bay Rays",
|
52 |
+
"Texas Rangers",
|
53 |
+
"Toronto Blue Jays",
|
54 |
+
"Washington Nationals"]
|
55 |
+
|
56 |
+
with gr.Blocks() as demo:
|
57 |
+
# gr.Image("../Documentation/Context Diagram.png", scale=2)
|
58 |
+
# gr(title="Your Interface Title")
|
59 |
+
gr.Markdown("""
|
60 |
+
<center>
|
61 |
+
<span style='font-size: 50px; font-weight: Bold; font-family: "Graduate", serif'>
|
62 |
+
MLB Score Predictor
|
63 |
+
</span>
|
64 |
+
</center>
|
65 |
+
""")
|
66 |
+
# gr.Markdown("""
|
67 |
+
# <center>
|
68 |
+
# <span style='font-size: 30px; line-height: 0.1; font-weight: Bold; font-family: "Graduate", serif'>
|
69 |
+
# Admin Dashboard
|
70 |
+
# </span>
|
71 |
+
# </center>
|
72 |
+
# """)
|
73 |
+
with gr.Row():
|
74 |
+
team = gr.Dropdown(choices = team_names, max_choices = 1, label="Team", scale=1)
|
75 |
+
|
76 |
+
with gr.Column():
|
77 |
+
inning = gr.Number(None, label="Inning", minimum = 1, maximum = 8, scale=1)
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
# with gr.Column():
|
81 |
+
venue = gr.Dropdown(choices = ["Home", "Away"], max_choices = 1, label="Home/Away Status", scale=1)
|
82 |
+
|
83 |
+
# with gr.Column():
|
84 |
+
hits = gr.Number(None, minimum=0, label="Hits - (H)", scale=1)
|
85 |
+
|
86 |
+
# summarize_btn = gr.Button(value="Summarize Text", size = 'sm')
|
87 |
+
|
88 |
+
with gr.Row():
|
89 |
+
with gr.Column():
|
90 |
+
errors = gr.Number(None, minimum=0, label="Errors - (E)", scale=1)
|
91 |
+
leftonbase = gr.Number(None, minimum=0, label="Left on Base - (LOB)", scale=1)
|
92 |
+
|
93 |
+
runs = gr.Number(None, minimum=0, label="Runs - (R)", scale=1)
|
94 |
+
|
95 |
+
with gr.Row():
|
96 |
+
predict_btn = gr.Button(value="Predict", size = 'sm')
|
97 |
+
|
98 |
+
with gr.Row():
|
99 |
+
final_score = gr.Textbox(label="Predicted Score", scale=1)
|
100 |
+
# patent_doc.upload(document_to_text, inputs = [patent_doc, slider, select_model], outputs=summary_doc)
|
101 |
+
predict_btn.click(predict, inputs=[team, inning, venue, hits, errors, leftonbase, runs], outputs=final_score)
|
102 |
+
|
103 |
+
demo.launch(inbrowser=True)
|