{"id":13490090,"url":"https://github.com/microsoft/lida","last_synced_at":"2025-05-14T03:09:01.531Z","repository":{"id":188854069,"uuid":"611913815","full_name":"microsoft/lida","owner":"microsoft","description":"Automatic Generation of Visualizations and Infographics using Large Language Models","archived":false,"fork":false,"pushed_at":"2024-08-08T18:44:15.000Z","size":509932,"stargazers_count":3029,"open_issues_count":80,"forks_count":335,"subscribers_count":43,"default_branch":"main","last_synced_at":"2025-05-07T23:47:00.099Z","etag":null,"topics":["cohere","datavisualization","hacktoberfest","llm","openai","openai-api","palm2","visualization"],"latest_commit_sha":null,"homepage":"https://microsoft.github.io/lida/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":"SECURITY.md","support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-09T19:58:55.000Z","updated_at":"2025-05-07T10:42:09.000Z","dependencies_parsed_at":"2023-09-27T01:18:47.472Z","dependency_job_id":"4960592e-1c9a-4603-a224-6bffd4332754","html_url":"https://github.com/microsoft/lida","commit_stats":{"total_commits":128,"total_committers":17,"mean_commits":7.529411764705882,"dds":0.296875,"last_synced_commit":"d892e20be0cf8263644f2575f097ccecebebf812"},"previous_names":["microsoft/lida"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Flida","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Flida/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Flida/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Flida/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/lida/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059508,"owners_count":22007768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cohere","datavisualization","hacktoberfest","llm","openai","openai-api","palm2","visualization"],"created_at":"2024-07-31T19:00:40.644Z","updated_at":"2025-05-14T03:09:01.498Z","avatar_url":"https://github.com/microsoft.png","language":"Jupyter Notebook","readme":"# LIDA: Automatic Generation of Visualizations and Infographics using Large Language Models\n\n[![PyPI version](https://badge.fury.io/py/lida.svg)](https://badge.fury.io/py/lida)\n[![arXiv](https://img.shields.io/badge/arXiv-2303.02927-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2303.02927)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/lida?label=pypi%20downloads)\n\n\u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/microsoft/lida/blob/main/notebooks/tutorial.ipynb\"\u003e\n\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/\u003e\n\u003c/a\u003e\n\n\u003c!-- \u003cimg src=\"docs/images/lidascreen.png\" width=\"100%\" /\u003e --\u003e\n\nLIDA is a library for generating data visualizations and data-faithful infographics. LIDA is grammar agnostic (will work with any programming language and visualization libraries e.g. matplotlib, seaborn, altair, d3 etc) and works with multiple large language model providers (OpenAI, Azure OpenAI, PaLM, Cohere, Huggingface). Details on the components of LIDA are described in the [paper here](https://arxiv.org/abs/2303.02927) and in this tutorial [notebook](notebooks/tutorial.ipynb). See the project page [here](https://microsoft.github.io/lida/) for updates!.\n\n\u003e **Note on Code Execution:**\n\u003e To create visualizations, LIDA _generates_ and _executes_ code.\n\u003e Ensure that you run LIDA in a secure environment.\n\n## Features\n\n![lida components](https://github.com/microsoft/lida/blob/main/docs/images/lidamodules.jpg?raw=true)\n\nLIDA treats _**visualizations as code**_ and provides a clean api for generating, executing, editing, explaining, evaluating and repairing visualization code.\n\n- [x] Data Summarization\n- [x] Goal Generation\n- [x] Visualization Generation\n- [x] Visualization Editing\n- [x] Visualization Explanation\n- [x] Visualization Evaluation and Repair\n- [x] Visualization Recommendation\n- [x] Infographic Generation (beta) # pip install lida[infographics]\n\n```python\n\nfrom lida import Manager, llm\n\nlida = Manager(text_gen = llm(\"openai\")) # palm, cohere ..\nsummary = lida.summarize(\"data/cars.csv\")\ngoals = lida.goals(summary, n=2) # exploratory data analysis\ncharts = lida.visualize(summary=summary, goal=goals[0]) # exploratory data analysis\n```\n\n## Getting Started\n\nSetup and verify that your python environment is **`python 3.10`** or higher (preferably, use [Conda](https://docs.conda.io/en/main/miniconda.html#installing)). Install the library via pip.\n\n```bash\npip install -U lida \n```\n\nLIDA depends on `llmx` and `openai`. If you had these libraries installed previously, consider updating them.\n\n```bash\npip install -U llmx openai\n```\n\nOnce requirements are met, setup your api key. Learn more about setting up keys for other LLM providers [here](https://github.com/victordibia/llmx).\n\n```bash\nexport OPENAI_API_KEY=\u003cyour key\u003e\n```\n\nAlternatively you can install the library in dev model by cloning this repo and running `pip install -e .` in the repository root.\n\n## Web API and UI\n\nLIDA comes with an optional bundled ui and web api that you can explore by running the following command:\n\n```bash\nlida ui  --port=8080 --docs\n```\n\nThen navigate to http://localhost:8080/ in your browser. To view the web api specification, add the `--docs` option to the cli command, and navigate to `http://localhost:8080/api/docs` in your browser.\n\nThe fastest and recommended way to get started after installation will be to try out the web ui above or run the [tutorial notebook](notebooks/tutorial.ipynb).\n\n## Building the Web API and UI with Docker\n\nThe LIDA web api and ui can be setup using docker and the command below (ensure that you have docker installed, and you have set your `OPENAI_API_KEY` environment variable).\n\n```bash\ndocker compose up\n```\n\n### Data Summarization\n\nGiven a dataset, generate a compact summary of the data.\n\n```python\nfrom lida import Manager\n\nlida = Manager()\nsummary = lida.summarize(\"data/cars.json\") # generate data summary\n```\n\n### Goal Generation\n\nGenerate a set of visualization goals given a data summary.\n\n```python\ngoals = lida.goals(summary, n=5, persona=\"ceo with aerodynamics background\") # generate goals\n```\n\nAdd a `persona` parameter to generate goals based on that persona.\n\n### Visualization Generation\n\nGenerate, refine, execute and filter visualization code given a data summary and visualization goal. Note that LIDA represents **visualizations as code**.\n\n```python\n# generate charts (generate and execute visualization code)\ncharts = lida.visualize(summary=summary, goal=goals[0], library=\"matplotlib\") # seaborn, ggplot ..\n```\n\n### Visualization Editing\n\nGiven a visualization, edit the visualization using natural language.\n\n```python\n# modify chart using natural language\ninstructions = [\"convert this to a bar chart\", \"change the color to red\", \"change y axes label to Fuel Efficiency\", \"translate the title to french\"]\nedited_charts = lida.edit(code=code,  summary=summary, instructions=instructions, library=library, textgen_config=textgen_config)\n\n```\n\n### Visualization Explanation\n\nGiven a visualization, generate a natural language explanation of the visualization code (accessibility, data transformations applied, visualization code)\n\n```python\n# generate explanation for chart\nexplanation = lida.explain(code=charts[0].code, summary=summary)\n```\n\n### Visualization Evaluation and Repair\n\nGiven a visualization, evaluate to find repair instructions (which may be human authored, or generated), repair the visualization.\n\n```python\nevaluations = lida.evaluate(code=code,  goal=goals[i], library=library)\n```\n\n### Visualization Recommendation\n\nGiven a dataset, generate a set of recommended visualizations.\n\n```python\nrecommendations = lida.recommend(code=code, summary=summary, n=2,  textgen_config=textgen_config)\n```\n\n### Infographic Generation [WIP]\n\nGiven a visualization, generate a data-faithful infographic. This methods should be considered experimental, and uses stable diffusion models from the [peacasso](https://github.com/victordibia/peacasso) library. You will need to run `pip install lida[infographics]` to install the required dependencies.\n\n```python\ninfographics = lida.infographics(visualization = charts[0].raster, n=3, style_prompt=\"line art\")\n```\n\n## Using LIDA with Locally Hosted LLMs (HuggingFace)\n\nLIDA uses the [llmx](https://github.com/victordibia/llmx) library as its interface for text generation. llmx supports multiple local models including HuggingFace models. You can use the huggingface models directly (assuming you have a gpu) or connect to an openai compatible local model endpoint e.g. using the excellent [vllm](https://vllm.readthedocs.io/en/latest/) library.\n\n#### Using HuggingFace Models Directly\n\n```python\n!pip3 install --upgrade llmx==0.0.17a0\n\n# Restart the colab session\n\nfrom lida import Manager\nfrom llmx import  llm\ntext_gen = llm(provider=\"hf\", model=\"uukuguy/speechless-llama2-hermes-orca-platypus-13b\", device_map=\"auto\")\nlida = Manager(text_gen=text_gen)\n# now you can call lida methods as above e.g.\nsumamry = lida.summarize(\"data/cars.csv\") # ....\n```\n\n#### Using an OpenAI Compatible Endpoint e.g. [vllm server](https://vllm.readthedocs.io/en/latest/getting_started/quickstart.html#openai-compatible-server)\n\n```python\nfrom lida import Manager, TextGenerationConfig , llm\n\nmodel_name = \"uukuguy/speechless-llama2-hermes-orca-platypus-13b\"\nmodel_details = [{'name': model_name, 'max_tokens': 2596, 'model': {'provider': 'openai', 'parameters': {'model': model_name}}}]\n\n# assuming your vllm endpoint is running on localhost:8000\ntext_gen = llm(provider=\"openai\",  api_base=\"http://localhost:8000/v1\", api_key=\"EMPTY\", models=model_details)\nlida = Manager(text_gen = text_gen)\n```\n\n## Important Notes / Caveats / FAQs\n\n- LIDA generates and executes code based on provided input. Ensure that you run LIDA in a secure environment with appropriate permissions.\n- LIDA currently works best with datasets that have a small number of columns (\u003c= 10). This is mainly due to the limited context size for most models. For larger datasets, consider preprocessing your dataset to use a subset of the columns.\n- LIDA assumes the dataset exists and is in a format that can be loaded into a pandas dataframe. For example, a csv file, or a json file with a list of objects. In practices the right dataset may need to be curated and preprocessed to ensure that it is suitable for the task at hand.\n- Smaller LLMs (e.g., OSS LLMs on Huggingface) have limited instruction following capabilities and may not work well with LIDA. LIDA works best with larger LLMs (e.g., OpenAI GPT 3.5, GPT 4).\n- How reliable is the LIDA approach? The LIDA [paper](https://aclanthology.org/2023.acl-demo.11/) describes experiments that evaluate the reliability of LIDA using a visualization error rate metric. With the current version of prompts, data summarization techniques, preprocessing/postprocessing logic and LLMs, LIDA has an error rate of \u003c 3.5% on over 2200 visualizations generated (compared to a baseline of over 10% error rate). This area is work in progress.\n- Can I build my own apps with LIDA? Yes! You can either use the python api directly in your app or setup a web api endpoint and use the web api in your app. See the [web api](#web-api-and-ui) section for more details.\n- How is LIDA related to OpenAI Code Interpreter: LIDA shares several similarities with code interpreter in the sense that both involve writing and executing code to address user intent. LIDA differs in its focus on visualization, providing a modular api for developer reuse and providing evaluation metrics on the visualization use case.\n\nNaturally, some of the limitations above could be addressed by a much welcomed PR.\n\n## Community Examples Built with LIDA\n\n- LIDA + Streamlit: [lida-streamlit](https://github.com/lida-project/lida-streamlit),\n\n## Documentation and Citation\n\nA short paper describing LIDA (Accepted at ACL 2023 Conference) is available [here](https://arxiv.org/abs/2303.02927).\n\n```bibtex\n@inproceedings{dibia2023lida,\n    title = \"{LIDA}: A Tool for Automatic Generation of Grammar-Agnostic Visualizations and Infographics using Large Language Models\",\n    author = \"Dibia, Victor\",\n    booktitle = \"Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)\",\n    month = jul,\n    year = \"2023\",\n    address = \"Toronto, Canada\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://aclanthology.org/2023.acl-demo.11\",\n    doi = \"10.18653/v1/2023.acl-demo.11\",\n    pages = \"113--126\",\n}\n```\n\nLIDA builds on insights in automatic generation of visualization from an earlier paper - [Data2Vis: Automatic Generation of Data Visualizations Using Sequence to Sequence Recurrent Neural Networks](https://arxiv.org/abs/1804.03126).\n","funding_links":[],"categories":["Jupyter Notebook","Microsoft Research","A01_文本生成_文本对话"],"sub_categories":["大语言对话模型及数据"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Flida","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoft%2Flida","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoft%2Flida/lists"}