{ "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": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(, '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": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(, '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 }