microsoft / lida

Automatic Generation of Visualizations and Infographics using Large Language Models
https://microsoft.github.io/lida/
MIT License
2.66k stars 282 forks source link

Haven't been able to generate a visualization with Altair #24

Open rmitra34 opened 12 months ago

rmitra34 commented 12 months ago

Hello, I've been playing around with the toolkit for a couple days and it's working very well with the seaborn Library. However I would like to generate VegaLite specifications so I switched to the altair library. However, I've been having issues with generating visualizations through this library. I am running the following code snippet to produce a visualization.

new_goal = Goal(index=1, question='Show the relationship between budget and rating', visualization='scatterplot', rationale='Both are quantitative attributes so a scatterplot is necessary to find the correlation')
goals.append(new_goal)
temp = Summary(name=summary['name'], file_name=summary['file_name'], dataset_description=summary['dataset_description'], field_names=summary['field_names'], fields=summary['fields'])
library="altair"
textgen_config = TextGenerationConfig(n=1, temperature=0.2, use_cache=True)
charts = lida.visualize(summary=temp, goal=new_goal, textgen_config=textgen_config, library=library) 
plot_raster(charts[0].raster)

The code block produces the following error:

Screenshot 2023-08-28 at 11 41 38 AM

Is there something wrong with how I'm switching the library to altair?

victordibia commented 12 months ago

Hi @rmitra34 ,

Thanks for trying this out. At the moment, visualize method returns a spec field when altair is the selected library. spec is a dictionary representation of the visualization. Currently, lida does does not return a visualization raster for altair (rendering altair visualizations in a headless manner is currently hairy).

You can then load this as follows

import altair as alt
spec = charts[0].spec 
new_chart = alt.Chart.from_dict(spec)
new_chart.data = lida.data
new_chart

I am thinking of ways to make this workflow better and will update here once I have something