Spaces:
Runtime error
Runtime error
# Import basis libraries | |
import pandas as pd | |
from pandasai import PandasAI | |
from pandasai.llm.starcoder import Starcoder | |
import matplotlib.pyplot as plt | |
#import gradio as gr | |
# Define List of Models | |
models = {"Starcoder": Starcoder} | |
#@title Select Model to Run | |
model_to_run = 'Starcoder' #@param [ "Starcoder", "Open-Assistant"] | |
#print(f"Enter API for {model_to_run} platform") | |
# Enter API Key | |
API_KEY = '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'#@param {type:"string"} | |
df = pd.DataFrame({ | |
"country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"], | |
"gdp": [21400000, 2940000, 2830000, 3870000, 2160000, 1350000, 1780000, 1320000, 516000, 14000000], | |
"happiness_index": [7.3, 7.2, 6.5, 7.0, 6.0, 6.3, 7.3, 7.3, 5.9, 5.0]}) | |
# Model Initialisation | |
llm = models[model_to_run](api_token=API_KEY) | |
pandas_ai = PandasAI(llm, save_charts =True, conversational=False, verbose=True) | |
# Enter Prompt related to data or Select from Pre-defined for demo purposes. | |
prompt = 'Plot the histogram of countries showing for each the gdp, using different colors for each bar' #@param [ "What is the relation between GDP and Happines Index", "Plot the histogram of countries showing for each the gpd, using different colors for each bar", "GDP of Top 5 Happiest Countries?"] {allow-input: true} | |
response = pandas_ai.run(df, prompt=prompt, | |
is_conversational_answer=False) | |
response.figure.savefig('chart.jpg') |