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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chat2plot-0.0.5.tar.gz.
File metadata
- Download URL: chat2plot-0.0.5.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed3d294dd9db886b63b8179b19101dc98ee17f235a8ff743d717918359bdd6dc
|
|
| MD5 |
26cfa722649378ee1de771309b9d0d86
|
|
| BLAKE2b-256 |
359473129af232f4f14d18c6fd55327b60249430774bbb678a52570d3da70f74
|
File details
Details for the file chat2plot-0.0.5-py3-none-any.whl.
File metadata
- Download URL: chat2plot-0.0.5-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
754d3c80cd10b54b54f54854d78c102d22bef5f36287952265d0c446e8425431
|
|
| MD5 |
f1e20ed94a192c37bc13a2b5df6c9402
|
|
| BLAKE2b-256 |
6b522be305b10e6773dc774ac3d8ff3986ae1692d925e49148c3c4ce70739c23
|