sxd3125's picture
Update app.py
aa6deca
raw
history blame
2.12 kB
# 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
def plot_chey(X):
a,b = X.figure, X.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, theme= 'snehilsanyal/scikit-learn') as demo:
gr.Markdown("# {}".format(heading))
button = gr.Button(value = 'submit')
button.click(plot_chey(response), outputs = gr.Plot())
demo.launch()
"""
with gr.Blocks(title=title) as demo:
gr.Markdown('''
<div>
<h1 style='text-align: center'>Plot</h1>
</div>
''')
button = gr.Button(value = 'nokku')
button.click(plot_chey, outputs = gr.Plot())
demo.launch()
"""