Spaces:
Runtime error
Runtime error
File size: 1,534 Bytes
47b09dd 6406ba1 47b09dd 6406ba1 00f2043 6406ba1 47b09dd 6406ba1 |
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 |
import gradio as gr
from pandas import DataFrame
from pandasai import PandasAI
from pandasai.llm.starcoder import Starcoder
from datasets import load_dataset
def send_prompt(token: str, df: DataFrame, prompt: str) -> str:
llm = Starcoder(api_token=token)
pandas_ai = PandasAI(llm, conversational=True)
return pandas_ai(df, prompt=prompt)
def get_result(token, dataset, config, split, prompt) -> str:
try:
dataset = load_dataset(dataset, config, split=split)
df = dataset.to_pandas()
return send_prompt(token, df, prompt=prompt)
except Exception as e:
return str(e)
with gr.Blocks() as demo:
gr.Markdown(" ## PandasAI demo using datasets library")
gr.Markdown(" pandasai library https://github.com/gventuri/pandas-ai")
gr.Markdown(" datasets library https://huggingface.co/docs/datasets/index")
hf_token = gr.Textbox(label="hugging face token", placeholder="hf_xxx", type="password")
dataset = gr.Textbox(label="dataset", placeholder="mstz/iris")
config = gr.Textbox(label="config", placeholder="iris")
split = gr.Textbox(label="split", placeholder="train")
prompt = gr.Textbox(label="prompt (str)", placeholder="How many records do I have?. Give me the median of sepal_width. Show me the first 5 rows.")
output = gr.Textbox(label="Output Box")
get_result_button = gr.Button("Submit")
get_result_button.click(get_result, inputs=[hf_token, dataset, config, split, prompt], outputs=output)
if __name__ == "__main__":
demo.launch()
|