-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Giving examples for dataframe component as a pandas.DataFrame
#2089
Comments
Hi @merveenoyan ! I think the follwoing should work import gradio as gr
import pandas as pd
examples = [[[[7, 8, 9], [10, 11, 12]]],
[[[5, 6, 7], [8, 9, 10]]]]
def get_max(df: pd.DataFrame) -> float:
return df.max().max()
gr.Interface(get_max, gr.DataFrame(type="pandas", headers=["a", "b", "c"]), gr.Number(),
examples=examples).launch() but I agree we should make it possible to pass a dataframe directly and fix the examples are displayed in the UI. |
So it's a list of lists of lists where each inner list is feature or sample? Can you specify? @freddyaboulton |
Hi @merveenoyan, in the latest released version of import gradio as gr
import pandas as pd
import numpy as np
examples = [[np.random.normal(size=(2,3)).tolist()], [np.random.normal(size=(2,3)).tolist()]]
def get_max(df: pd.DataFrame) -> float:
return df.max().max()
gr.Interface(get_max, gr.DataFrame(type="pandas", headers=["a", "b", "c"]), gr.Number(),
examples=examples).launch() |
If you build from source from import gradio as gr
import pandas as pd
import numpy as np
examples = [["test.csv"]]
def get_max(df: pd.DataFrame) -> float:
return df.max().max()
gr.Interface(get_max, gr.DataFrame(type="pandas", headers=["a", "b", "c"]), gr.Number(),
examples=examples).launch() but the preview looks weird. I'll create an issue around that Does that cover what you are looking to do? |
@merveenoyan Yea in general, the data for the examples parameter is a list of lists, where each element of the inner list is the data for that particular component. In the case of a DataFrame, the “data for that particular component”, is a list of lists where each inner list is a row of the dataframe. In the future, I think we can make passing a pandas dataframe work so it’s easier to specify: examples = [[pd.DataFrame(…)], [pd.DataFrame(…)]] Edit: whoops @abidlabs commented while I was typing this out 😂 |
Thanks a lot, I will try these! |
@freddyaboulton in theory, the @merveenoyan mind if I reopen this issue to track this feature? |
pandas.DataFrame
@abidlabs I remember seeing that as well that I had to give as a list of lists, it makes more sense to give as a pandas dataframe (it's more native when you think about it). |
Hey hey, it works fine! (on my local at least 😅) thanks a lot! |
I’m trying to give examples to dataframe component as list of lists like we do with other things, however I couldn’t succeed. when I look at the documentation, it doesn’t exist in the example as well. The example is not parsed correctly.
The list of lists is [[header1_row_1 header2_row1 ..] [header2_row1, header2_row2 ...]] where headers are features and rows are values. Each inner list is a sample (see example below)
It also gets each input and divides the string and treats it weirdly (see screenshot below) (it says
m a t ..
for first example as you can see, where it'smaterial_7
)Also on Spaces, I get "list index out of range" for the above reason.
Can you tell me what am I doing wrong?
The text was updated successfully, but these errors were encountered: