pandas-ai icon indicating copy to clipboard operation
pandas-ai copied to clipboard

code not generated due to missing libs in whitelist

Open sandiemann opened this issue 1 year ago • 1 comments

🐛 Describe the bug

After the latest release, the example did not generate code due to missing libs in whitelist,

import pandas as pd
  ...: 
  ...: from pandasai import PandasAI
  ...: from pandasai.llm.openai import OpenAI
  ...: 
  ...: from examples.data.sample_dataframe import dataframe
  ...: 
  ...: df = pd.DataFrame(dataframe)
  ...: 
  ...: llm = OpenAI()
  ...: pandas_ai = PandasAI(llm, verbose=True, conversational=False)
  ...: response = pandas_ai(df, "Calculate the sum of the gdp of north american countries")
  ...: print(response)
  ...: 
Running PandasAI with openai LLM...
Code generated:
import pandas as pd
# create dataframe
data = {'country': ['United Kingdom', 'France', 'Italy', 'Germany', 'United States', 'Canada', 'Mexico', 'Brazil', 'Argentina', 'Chile'],
        'gdp': [1745433788416, 7191747985, 5659112121, 2655246018, 4538789365, 1785387456, 1218745698, 2145789654, 987456321, 789456123],
        'happiness_index': [7.16, 7.07, 6.38, 6.38, 7.16, 7.23, 6.77, 6.95, 6.08, 6.44]}
df = pd.DataFrame(data)
# calculate sum of gdp for North American countries
north_america = ['United States', 'Canada', 'Mexico']
sum_gdp = df[df['country'].isin(north_america)]['gdp'].sum()
print(sum_gdp)
                
Unfortunately, I was not able to answer your question, because of the following error:
Generated code includes import of pandas which is not in whitelist.

sandiemann avatar Jun 02 '23 20:06 sandiemann

Same scenario for the chart example,

import pandas as pd
  ...: 
  ...: from pandasai import PandasAI
  ...: from pandasai.llm.openai import OpenAI
  ...: 
  ...: from examples.data.sample_dataframe import dataframe
  ...: 
  ...: df = pd.DataFrame(dataframe)
  ...: 
  ...: llm = OpenAI()
  ...: pandas_ai = PandasAI(llm, save_charts=True)
  ...: response = pandas_ai(
  ...:     df,
  ...:     "Plot the histogram of countries showing for each the gpd, using different colors for each bar"
  ...: )
  ...: print(response)
  ...: 
Unfortunately, I was not able to answer your question, because of the following error:
Generated code includes import of matplotlib.pyplot which is not in whitelist.

sandiemann avatar Jun 02 '23 20:06 sandiemann

Hey @sandiemann , Are you familiar with how to actually set ui the GUI for pandas.ai charts with streamlit?

Dominiq1 avatar Jun 06 '23 20:06 Dominiq1