Spaces:
Runtime error
Runtime error
File size: 5,884 Bytes
fed5724 e71753a fed5724 e71753a fed5724 e71753a fed5724 e71753a fed5724 e71753a fed5724 e71753a fed5724 e15571e e71753a fed5724 e71753a fed5724 |
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4826cf16",
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display, HTML\n",
"import pandas as pd\n",
"from fastai.tabular.all import *\n",
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "34fc127c",
"metadata": {},
"outputs": [],
"source": [
"path = Path()\n",
"df = pd.read_csv(\"rookie_year.csv\")\n",
"learn = load_learner(path/\"export.pkl\")\n",
"columns = [\"Name\", \"G\", \"GS\", \"Cmp\", \"Att\", \"Yds\", \"Cmp%\", \"TD\", \"Int\", \"Y/G\", \"Sk\"]"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "6e82eaae",
"metadata": {},
"outputs": [],
"source": [
"def predict(data):\n",
" row = df[df[\"Name\"] == data]\n",
" row = row.loc[:, ~df.columns.str.contains('^Unnamed')]\n",
" if not len(row):\n",
" print(\"ERROR: No QB in database with this name\")\n",
" return \n",
" pred_row, clas, probs = learn.predict(row.iloc[0])\n",
" prediction = pred_row.decode()[\"Tier\"].item() \n",
" return row[columns], prediction\n"
]
},
{
"cell_type": "code",
"execution_count": 81,
"id": "b9242a91",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7866/\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(<gradio.routes.App at 0x26e1100f1c0>, 'http://127.0.0.1:7866/', None)"
]
},
"execution_count": 81,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"demo = gr.Interface(fn=predict, \n",
" inputs=\"text\", \n",
" outputs=[\n",
" gr.Dataframe(row_count=1, col_count=11, headers=columns, label=\"Rookie Year Stats\"), \n",
" gr.Textbox(label=\"Prediction\")\n",
" ],\n",
" title=\"Rookie QB Career Prediction (Name)\",\n",
" description=\"Given Name of QB who has played in the NFL, predict their career tier. Uses data from https:\\/\\/www.pro-football-reference.com. Tiers based on PFR Approximate Value.\",\n",
" article=\"See more details at https://github.com/mhrice/Rookie-QB-Predictions\"\n",
" examples=[\"Tom Brady\", \"Joe Burrow\", \"Trevor Lawrence\"]\n",
" )\n",
"\n",
"demo.launch()"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "46d819f7",
"metadata": {},
"outputs": [],
"source": [
"def predict2(data):\n",
" row = data.drop(\"Name\", axis=1).astype(float)\n",
" row[\"Cmp\"] = row[\"Att\"].item() * row[\"Cmp%\"].item()\n",
" pred_row, clas, probs = learn.predict(row.iloc[0])\n",
" prediction = pred_row.decode()[\"Tier\"].item() \n",
" return prediction\n"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "dd0aae3a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7865/\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7865/\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(<gradio.routes.App at 0x26e10daa310>, 'http://127.0.0.1:7865/', None)"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"demo2 = gr.Interface(fn=predict2, \n",
" inputs=gr.Dataframe(row_count=1, col_count=8, headers=[x for x in columns if x not in [\"Cmp\", \"G\", \"GS\"]], label=\"Rookie Year Stats\"), \n",
" outputs=gr.Textbox(label=\"Prediction\"),\n",
" title=\"Rookie QB Career Prediction (Stats)\",\n",
" description=\"Given stats of a presumed rookie QB, predict their career tier. Uses data from https:\\/\\/www.pro-football-reference.com. Tiers based on PFR Approximate Value.\",\n",
" article=\"See more details at https://github.com/mhrice/Rookie-QB-Predictions\"\n",
" )\n",
"\n",
"demo2.launch()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c7e8cbe",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|