File size: 4,192 Bytes
b355641
 
9695c60
b355641
 
 
 
 
 
9695c60
b355641
 
9695c60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: NFL Receiving Yards Predictor
emoji: πŸ“Š
colorFrom: purple
colorTo: red
sdk: gradio
sdk_version: 5.49.0
app_file: app.py
pinned: false
license: mit
---

# 🏈 NFL Receiving Yards Predictor

This interactive Gradio app predicts **NFL receiving yards** for any active wide receiver or tight end based on the quarterback, game week, stadium conditions, and real-time weather forecasts.
The model leverages **AutoGluon Tabular** for regression and integrates **player embeddings**, **team data**, and **environmental context** for enhanced accuracy.

---

## πŸš€ Demo

Try it live here: [Hugging Face Space](https://huggingface.co/spaces/SebastianAndreu/2025-24679-NFL-Yards-Predictor)

---

## 🧠 Model Overview

* **Model Type:** Tabular Regression
* **Framework:** [AutoGluon Tabular](https://auto.gluon.ai/stable/tutorials/tabular_prediction/index.html)
* **Training Dataset:** Aggregated play-by-play and player stats from NFL seasons
* **Input Features Include:**

  * Receiver & quarterback IDs (with learned embeddings)
  * Team and opponent IDs
  * Stadium type and surface
  * Game spread and total line
  * Weather conditions (temperature, humidity, wind, precipitation)
  * Home/Away team indicators

---

## βš™οΈ How It Works

1. The app loads the pre-trained AutoGluon predictor and historical player embeddings from the Hugging Face model repo:

   ```
   SebastianAndreu/2025-24679-NFL-Yards-Predictor
   ```
2. Users select:

   * Receiver
   * Quarterback
   * Week
   * Season
3. The app fetches:

   * Game info (from local CSVs)
   * Real-time weather forecast (via [Open-Meteo API](https://open-meteo.com/))
4. The combined data is passed into the predictor for inference.
5. The model outputs the **expected receiving yards** for that matchup.

---

## πŸ“ Repository Structure

```
.
β”œβ”€β”€ app.py                   # Main Gradio interface and logic
β”œβ”€β”€ players.csv              # Active player metadata
β”œβ”€β”€ games.csv                # Game schedule and context
β”œβ”€β”€ hf_assets/               # Cached model assets from Hugging Face
β”œβ”€β”€ nfl_model/               # Snapshot of downloaded model files
β”œβ”€β”€ README.md                # You are here
```

---

## 🧩 Key Functions

### `download_model_and_embeddings()`

Downloads and prepares the AutoGluon model and the player embedding dataset from Hugging Face.

### `get_game_info()`

Matches the selected receiver’s team, week, and season to the corresponding game, including opponent and stadium metadata.

### `get_weather_forecast()`

Fetches real-time forecast for the stadium using **Open-Meteo**, returning temperature, humidity, wind speed, and rain/snow conditions.

### `predict_yards()`

Prepares the full feature vector and runs inference using the AutoGluon predictor. If missing embeddings are detected, they’re replaced by mean values for stability.

---

## 🧰 Requirements

To run locally:

```bash
pip install gradio autogluon tabular pandas requests huggingface_hub
```

---

## 🌀️ Weather API Integration

The app dynamically queries the [Open-Meteo](https://open-meteo.com/) API based on the selected stadium coordinates.
Example usage:

```python
https://api.open-meteo.com/v1/forecast?latitude=40.4468&longitude=-80.0158&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m,weather_code
```

---

## 🏟️ Stadium Metadata

Each NFL stadium’s coordinates are stored in the `STADIUM_COORDS` dictionary to map weather forecasts accurately.

---

## 🏈 Credits

* **Developer:** [Sebastian Andreu](https://huggingface.co/SebastianAndreu)
* **Model:** AutoGluon Tabular Regression trained on historical NFL data
* **APIs:** Open-Meteo (Weather), ESPN (Game Schedule)
* **Hosted on:** [Hugging Face Spaces](https://huggingface.co/spaces/SebastianAndreu/2025-24679-NFL-Yards-Predictor)

---

## 🧾 License

MIT License Β© 2025 Sebastian Andreu

---

## πŸ’¬ Feedback

If you find a bug or have a feature suggestion, please open an issue on the [model repository](https://huggingface.co/SebastianAndreu/2025-24679-NFL-Yards-Predictor).


Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference