Spaces:
Sleeping
Sleeping
File size: 2,979 Bytes
9bb522b d95bed5 9bb522b d95bed5 9bb522b 96c33b9 d95bed5 96c33b9 d95bed5 96c33b9 | 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 | ---
title: My Fastapi Endpoint
emoji: 🏃
colorFrom: gray
colorTo: purple
sdk: docker
pinned: false
license: mit
---
# Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
title: My FastAPI App
emoji: 🌍
colorFrom: red
colorTo: red
sdk: docker
pinned: false
license: mit
short_description: This is a taxi predictor!
---
# FastAPI Taxi Trip Duration Prediction API
This project provides a FastAPI-based REST API for predicting taxi trip durations in different cities using pre-trained Ridge regression models.
## How to Use
### 1. Running the API
- **Locally:**
Start the server with:
```sh
uvicorn main:app --host 0.0.0.0 --port 7860
```
- **On Hugging Face Spaces:**
The API will be available at
`https://<your-username>-<your-space-name>.hf.space/predict`
### 2. Sending a Prediction Request
You can send a POST request to the `/predict` endpoint using any HTTP client (such as `curl`, Postman, or Python's `requests` library).
#### Example Python snippet
```python
import requests
API_URL = "https://<your-username>-<your-space-name>.hf.space/predict"
# If your Space is private, uncomment and set your token:
# HF_TOKEN = "hf_xxx..."
# headers = {"Authorization": f"Bearer {HF_TOKEN}"}
headers = {}
data = {
"vendor_id": "Bogotá UberX",
"dist_meters": 18.976,
"wait_sec": 1640,
"geodetic_dist": 15.439039,
"mean_velocity": 17.172851,
"is_rush_hour": False,
"model_name": "bog"
}
response = requests.post(API_URL, json=data, headers=headers)
print(response.json())
```
### 3. Datapoint Format
The API expects a JSON object with the following fields:
| Field | Type | Example Value | Description |
| ------------- | ------ | -------------- | ------------------------------------------------ |
| vendor_id | string | "Bogotá UberX" | The taxi vendor or service name |
| dist_meters | float | 18.976 | Distance of the trip in meters |
| wait_sec | float | 1640 | Waiting time in seconds |
| geodetic_dist | float | 15.439039 | Geodetic (straight-line) distance |
| mean_velocity | float | 17.172851 | Mean velocity during the trip |
| is_rush_hour | bool | false | Whether the trip occurred during rush hour |
| model_name | string | "bog" | Which model to use: `"bog"`, `"mex"`, or `"uio"` |
**Example JSON datapoint:**
```json
{
"vendor_id": "Bogotá UberX",
"dist_meters": 18.976,
"wait_sec": 1640,
"geodetic_dist": 15.439039,
"mean_velocity": 17.172851,
"is_rush_hour": false,
"model_name": "bog"
}
```
### 4. Response Format
The API will return a JSON response like:
```json
{
"trip_duration": 123.45,
"model_used": "bog",
"message": "Inference successful using BOG model."
}
```
---
> > > > > > > 531d625 (Commiiitt!)
|