chat to visualization with LLM
Project description
📈 Chat2Plot - interactive text-to-visualization with LLM
Chat2plot is a project that provides visualizations based on chat instructions for given data.
demo: https://chat2plot-sample.streamlit.app/
Usage
import os
import pandas as pd
from chat2plot import chat2plot
# 1. Set api-key
os.environ["OPENAI_API_KEY"] = "..."
df = pd.read_csv(...)
# 2. Pass a dataframe to draw
c2p = chat2plot(df)
# 3. Make a question about the data
result = c2p("average target over countries")
result.figure.show() # draw a plot
print(result.config) # get a config (json / dataclass)
print(result.explanation) # see the explanation generated by LLM
# you can make follow-up request to refine the chart
result = c2p("change to horizontal-bar chart")
result.figure.show()
# draw a chart inside chat2plot
_ = c2p("filter data to asia region", show_plot=True)
Why Chat2Plpot
Inside Chat2Plot, LLM does not generate Python code, but generates plot specifications in json.
The declarative visualization specification in json is transformed into actual charts in Chat2Plot using plotly or altair, but users can also use json directly in their own applications.
This design limits the visualization expression compared to Python code generation (such as ChatGPT's Code Interpreter Plugin), but has the following practical advantages:
-
Secure
- More secure execution, as LLM does not directly generate code.
-
Language-independent
- Declarative data structures are language-agnostic, making it easy to plot in non-Python environments.
-
Interactive
- Declarative data can be modified by the user to improve plots through collaborative work between the user and LLM.
The json schema can be selected from a default simple definition or a vega-lite compliant schema.
c2p = chat2plot(df, "vega") # use vega-lite format
ret = c2p("plot x vs y")
ret.config # get vega-lite compliant json data
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for chat2plot-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d194169fd6ee735a47a579e98f5251bdf6e0c64b8ae7f9c17cc7abed1eec2b75 |
|
MD5 | 2a5e271a14c1789a3c3a67ac4eac46bc |
|
BLAKE2b-256 | b43b5c9a9ca9ede777f0ac5da7738f5c54b59673fbb7c36ee9b5363becfd797b |