Spaces:
Sleeping
Sleeping
metadata
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:uvicorn main:app --host 0.0.0.0 --port 7860 - On Hugging Face Spaces:
The API will be available athttps://<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
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:
{
"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:
{
"trip_duration": 123.45,
"model_used": "bog",
"message": "Inference successful using BOG model."
}
531d625 (Commiiitt!)