asoria HF staff commited on
Commit
6406ba1
1 Parent(s): 47b09dd

First test

Browse files
Files changed (6) hide show
  1. .python-version +1 -0
  2. app.py +32 -4
  3. packages.txt +2 -0
  4. poetry.lock +0 -0
  5. poetry.toml +3 -0
  6. pyproject.toml +15 -0
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.9.15
app.py CHANGED
@@ -1,7 +1,35 @@
1
  import gradio as gr
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from pandas import DataFrame
3
+ from pandasai import PandasAI
4
+ from pandasai.llm.starcoder import Starcoder
5
+ from datasets import load_dataset
6
 
7
+ def send_prompt(token: str, df: DataFrame, prompt: str) -> str:
8
+ llm = Starcoder(api_token=token)
9
+ pandas_ai = PandasAI(llm, conversational=False)
10
+ return pandas_ai(df, prompt=prompt)
11
 
12
+ def get_result(token, dataset, config, split, prompt) -> str:
13
+ try:
14
+ dataset = load_dataset(dataset, config, split=split)
15
+ df = dataset.to_pandas()
16
+ return send_prompt(token, df, prompt=prompt)
17
+ except Exception as e:
18
+ return str(e)
19
+
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown(" ## PandasAI demo using datasets library")
22
+ gr.Markdown(" pandasai library https://github.com/gventuri/pandas-ai")
23
+ gr.Markdown(" datasets library https://huggingface.co/docs/datasets/index")
24
+
25
+ hf_token = gr.Textbox(label="hugging face token", placeholder="hf_xxx", type="password")
26
+ dataset = gr.Textbox(label="dataset", placeholder="mstz/iris")
27
+ config = gr.Textbox(label="config", placeholder="iris")
28
+ split = gr.Textbox(label="split", placeholder="train")
29
+ 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.")
30
+ output = gr.Textbox(label="Output Box")
31
+ get_result_button = gr.Button("Submit")
32
+ get_result_button.click(get_result, inputs=[hf_token, dataset, config, split, prompt], outputs=output)
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch()
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pandasai
2
+ datasets
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
poetry.toml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [virtualenvs]
2
+ in-project = true
3
+ prefer-active-python = true
pyproject.toml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "pandasai-datasets-demo"
3
+ version = "0.1.0"
4
+ description = "Demo for pandasai using datasets library"
5
+ authors = ["Andrea Soria <andrea@huggingface.co>"]
6
+
7
+ [tool.poetry.dependencies]
8
+ gradio = "3.28.1"
9
+ python = "^3.9.15"
10
+ pandasai = "^0.2.14"
11
+ datasets = "^2.12.0"
12
+
13
+ [build-system]
14
+ requires = ["poetry-core"]
15
+ build-backend = "poetry.core.masonry.api"