Metadata-Version: 2.1
Name: chat2plot
Version: 0.0.7
Summary: chat to visualization with LLM
Home-page: https://github.com/nyanp/chat2plot
Author: nyanp
Author-email: Noumi.Taiga@gmail.com
License: MIT
Keywords: llm visualization chart gpt
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: altair (>=4.2.0)
Requires-Dist: commentjson (==0.9.0)
Requires-Dist: jsonschema
Requires-Dist: jsonref
Requires-Dist: langchain (>=0.0.127)
Requires-Dist: openai (>=0.27.0)
Requires-Dist: pandas (>=1.5.0)
Requires-Dist: plotly (>=5.0.0)
Requires-Dist: pydantic (>=1.9.0)
Requires-Dist: streamlit-chat (>=0.0.2.2)
Requires-Dist: tabulate
Requires-Dist: vegafusion[embed] (>=1.0)

# 📈 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

```Python
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.

```Python
c2p = chat2plot(df, "vega")  # use vega-lite format

ret = c2p("plot x vs y")

ret.config  # get vega-lite compliant json data
```
