Spaces:
Runtime error
Runtime error
File size: 1,835 Bytes
99438f3 0a252c0 76e016c fde343f d7dc696 c35f02a 8ab30ec 6f77700 2fabb36 99438f3 d7dc696 99438f3 058b6c6 99438f3 539a9b1 d7dc696 99438f3 13a59ec d7dc696 99438f3 fd4897e 797592e 146b72c aa6deca d7dc696 a8f5870 d7dc696 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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
#function to plot
def plot_response():
a,b = response.figure, response.axes
return a
title='Plot'
# 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)
heading = 'Pandas AI : Dataframe analytics using text prompt'
with gr.Blocks(title = heading) as demo:
gr.Markdown("# {}".format(heading))
button = gr.Button(value = 'click to generate plot')
button.click(plot_response, outputs = gr.Plot())
demo.launch() |