AI powered census data
Tags: python, openai, ai, github
Published: 2023-03-10 15:00:48

Mr [Ligma](https://twitter.com/TitterDaily/status/1586058051177455616) took some time away from unemployment to share his latest public works project, [CensusGPT](https://censusgpt.com/). 

{% twitter 1633992774394544128 %}

Thanks to AI we are all one chat prompt from being a Data Scientist.

_header image was generated using [midjourney](https://www.midjourney.com/app/jobs/8d92d957-b135-49f1-bb29-de223e2108de/)_

{% github caesarHQ/textSQL noreadme %}
## What is caesarHQ/textSQL?
Several projects in the USA provide tools, like [Civin](https://civin.co/), for civic planners to organize and orchestrate the collection of civic data. This tool allows the data scientist to ask any question based on USA Census data. Adding ChatGPT interaction to get answers is a chef's kiss.

With the addition of OpenAI tools, you can start seeing the potential of where this can go for understanding large amounts of City data. Excited to see what other ideas come out of this.  

## How does it work?
This open-source project from [caesarHQ](https://github.com/caesarHQ) leverages the new ChatGPT API to ingest data and present answers on the cities with publicly viewable data.

_code snippet from [api/app/api/utils.py](https://github.com/caesarHQ/textSQL/blob/c6bf191ac792263261cabadcfb34c4f2fb1ed690/api/app/api/utils.py#L123)_
```python
# api/app/api/utils.py

def get_assistant_message(
        temperature: int = 0,
        model: str = "gpt-3.5-turbo", # ChatGPT API
        messages: List[Dict[str, str]] = DEFAULT_MESSAGES,
        ) -> str:
    res = openai.ChatCompletion.create(
            model=model,
            temperature=temperature,
            messages=messages
        )
    # completion = res['choices'][0]['message']['content']
    assistant_message = res['choices'][0]
    return assistant_message
```
Interesting is that they present the SQL queries in the browser. This allows the user, probably a data engineer, to leave the answers and continue work. My SQL injection days make me cringe at this, but their queries are read-only. 

![sql queries](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ukhj36lwlztc6qbkh9z.png)

As mentioned in previous posts, I am not as familiar with Python in this series, but it looks like the project is using [SQLAlchemy](https://www.sqlalchemy.org/) to access the hosted database and run queries there. Files reference the models and tables in the [models](https://github.com/caesarHQ/textSQL/tree/main/api/app/models) folder.

OpenAI, especially the ChatGPT API does well with a data source. The little I know about Machine Learning is that you need a lot of data to get good results, and cities have been sourcing public data for years, making this problem approachable through AI. I look forward to sharing more examples like this in future posts.

Also, if you have a project leveraging OpenAI or similar, leave a link in the comments. I'd love to take a look and include it in my [9 days of OpenAI series](https://dev.to/bdougieyo/30-days-of-openai-1ek6).

_Find more AI projects using [OpenSauced](https://insights.opensauced.pizza/ai/repositories/filter/recent)_

Stay saucy.