chat2plot  by nyanp

LLM-powered tool for converting natural language into visualizations

created 2 years ago
259 stars

Top 98.4% on sourcepulse

GitHubView on GitHub
Project Summary

This library enables users to generate data visualizations and explanations from natural language queries using Large Language Models (LLMs). It targets data analysts and researchers who need to quickly explore and present data without writing code. The primary benefit is a secure, language-independent, and interactive way to create charts by having the LLM output declarative JSON specifications rather than executable code.

How It Works

Chat2Plot leverages LLMs to translate natural language requests into high-level chart specifications in JSON format, supporting both a simple internal format and Vega-Lite. This declarative approach is advantageous because it enhances security by preventing the LLM from generating executable code, making it language-independent for use in non-Python environments, and enabling interactive refinement of plots through user-LLM collaboration. The generated JSON specifications are then rendered into actual charts using libraries like Plotly or Altair.

Quick Start & Requirements

  • Install: pip install chat2plot
  • Prerequisites: OpenAI API key set as an environment variable (OPENAI_API_KEY).
  • Usage:
    import os
    import pandas as pd
    from chat2plot import chat2plot
    
    os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"
    df = pd.read_csv("your_data.csv")
    c2p = chat2plot(df)
    result = c2p("average target over countries")
    result.figure.show()
    
  • Documentation: https://chat2plot-sample.streamlit.app/

Highlighted Details

  • Supports custom LLMs (e.g., AzureChatOpenAI) and Vega-Lite schema definitions.
  • Allows defining custom chart schemas using Pydantic models.
  • Offers language specification for explanations and a privacy-preserving description_strategy="dtypes" option.
  • Outputs include the generated figure, chart configuration (JSON/dataclass), and LLM-generated explanations.

Maintenance & Community

The project is maintained by nyanp. Further community or roadmap information is not detailed in the README.

Licensing & Compatibility

The README does not explicitly state a license. Compatibility for commercial use or closed-source linking is not specified.

Limitations & Caveats

The declarative JSON output limits visualization expressiveness compared to direct code generation. The default model is gpt-3.5-turbo-0613, and OpenAI API keys are required, which may have cost implications.

Health Check
Last commit

1 year ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
15 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Chris Van Pelt Chris Van Pelt(Cofounder of Weights & Biases), and
3 more.

lida by microsoft

0.2%
3k
Library for LLM-driven data visualization and infographic generation
created 2 years ago
updated 11 months ago
Feedback? Help us improve.