Weather Peru API is an app designed to showcase how gpt-3.5-turbo can be used to interact with data in natural language. The API uses weather records from various meteorological stations across Peru to respond to natural language queries. Please note that the project does not come with data preloaded, and you will need to download the necessary data from the official website of SENAMHI before uploading it for use in the app.
- Clone this repository:
git clone https://github.com/IvanHerreraCasas/weather_peru_api.git
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
source venv/bin/activate
(Linux/Mac) orvenv\Scripts\activate
(Windows) - Install the required packages:
pip install -r requirements.txt
- In the root directory create a new file
.env
with the following lines
SQLALCHEMY_DATABASE_URI=<YOUR_DATABASE_URI>
OPENAI_API_KEY=<YOUR_KEY>
- Run the app:
flask run
- Upload your data (more details in usage section)
Create a new or save a station.
{
"name": "San Miguel",
"region": "Piura",
"province": "Piura",
"district": "Castilla"
}
Returns a list of all available stations in the specified region, province, district.
{
"region": "Piura"
}
[
{
"district": "Piura",
"id": 5,
"name": "Miraflores",
"province": "Piura",
"region": "Piura"
},
{
"district": "Marvelica",
"id": 6,
"name": "Mallares",
"province": "Sullana",
"region": "Piura"
},
{
"district": "Catacaos",
"id": 7,
"name": "San Miguel",
"province": "Piura",
"region": "Piura"
}
]
Upload and save a new records file.
{
"station_name": "Catacaos"
}
{
"file": "path/catacaos.txt"
}
Returns a list of records that meet the specified conditions: date range, location, and station name.
{
"start_date": "1998-03-22",
"end_date": "1998-03-22",
"region": "Piura",
"province": "Piura"
}
[
{
"date": "1998-03-22",
"id": 41082,
"max_temp": 35.0,
"min_temp": 25.2,
"precipitation": 75.0,
"station_name": "Miraflores"
},
{
"date": "1998-03-22",
"id": 95135,
"max_temp": 34.5,
"min_temp": 23.2,
"precipitation": 34.0,
"station_name": "San Miguel"
}
]
This is the main endpoint of this API. It receives natural language questions related to weather records from Peru and responds with the relevant information. The questions can be related to specific weather records, statistical information, or averages.
GET
{
"question": "What was the day with highest precipitation in Sullana."
}
{
"answer": "The highest precipitation in Sullana was recorded on March 22, 1998, with 201mm. The temperature was between 24.5°C and 35.2°C. The station named \"Mallares\" registered this weather record.",
"function_result": {
"id": 60440,
"date": "1998-03-22",
"precipitation": 201.0,
"max_temp": 35.2,
"min_temp": 24.5,
"station_name": "Mallares"
}
}
{
"question": "What was the average max temperature in Piura, Piura from 2000 to 2015?"
}
{
"answer": "The average max temperature in Piura, Piura from 2000 to 2015 was 30.8 degrees Celsius.",
"function_result": 30.837992986989494
}
This endpoint returns the weather record with the highest or lowest value of a specified parameter in the specified conditions.
{
"stat_type": "max",
"parameter": "precipitation",
"region": "Piura",
"province": "Sullana"
}
{
"record": {
"date": "2011-03-11",
"id": 84716,
"max_temp": 38.6,
"min_temp": 19.9,
"precipitation": 0.0,
"station_name": "Mallares"
}
}
Return a statistical value (average, ...) in the specified conditions.
{
"stat_type": "average",
"parameter": "max_temp",
"region": "Piura",
"province": "Piura"
}
{
"value": 30.614071868307963
}
The Weather Peru API project demonstrates how natural language processing and machine learning can be used to make data more accessible to non-technical users. This API provides an intuitive and user-friendly interface for querying weather records in Peru. Users can interact with the data using conversational language, making the data more accessible to people who may not have the technical expertise required to use traditional data analysis tools. This API can be easily extended to include data from other regions or weather parameters, providing a powerful tool for exploring and understanding weather patterns in Peru.