DEV Community

Cover image for AI powered census data
Brian Douglas
Brian Douglas

Posted on • Edited on

AI powered census data

Mr Ligma took some time away from unemployment to share his latest public works project, CensusGPT.

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

header image was generated using midjourney

What is caesarHQ/textSQL?

Several projects in the USA provide tools, like Civin, 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 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



# 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


Enter fullscreen mode Exit fullscreen mode

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

As mentioned in previous posts, I am not as familiar with Python in this series, but it looks like the project is using SQLAlchemy to access the hosted database and run queries there. Files reference the models and tables in the 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.

Find more AI projects using OpenSauced

Stay saucy.

Top comments (0)