-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Dataframe examples problem #10723
Comments
Hi @caglarari can you provide a minimal example with correctly formatted code we can use to reproduce the issue? The example provided here is not minimal and not formatted. |
Hi, |
Hi @caglarari would you please be able to provide a minimal example that we can use to reproduce the issue above? See: https://stackoverflow.com/help/minimal-reproducible-example |
Here |
Hi @caglarari I just tested on the latest version of Gradio (5.20.1) and the issue is resolved. We previously had an issue where headers needed to be strings but we've sinced fixed this. Please upgrade your local version of Gradio or the ![]() |
Describe the bug
The code below that uses Gradio dataframe with pandas dataframe examples used to work but I tried it on Hugging Face & it doesn't work anymore. It doesn't work with an older Gradio version 3.50.2 either. When I tried it with version 3.50.2, Gradio treated the first row of the pandas data frame as string / header but it shouldn't since Xhpd=pd.read_csv("data_NB.csv",header=None)
Any idea how can I fix this problem?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from copy import deepcopy
import time
import gradio as gr
plt.rcParams['figure.figsize'] = [10, 10]
plt.rcParams['figure.dpi'] = 100
Xhpd=pd.read_csv("data_NB.csv",header=None)
yhpd=pd.read_csv("labels_NB.csv",header=None)
def visualise_gr(models,names,lsData,inTitle="Data Set",kNum=200,th=0.001):
fig=plt.figure()
plt.scatter(lsData[0][:,0],lsData[0][:,1], color='red')
plt.scatter(lsData[1][:,0],lsData[1][:,1], color='blue')
plt.xticks(range(0,11))
plt.yticks(range(0,11))
plt.xlabel("X")
plt.ylabel("Y")
plt.grid()
plt.title(inTitle)
#
plt.axis('scaled')
print("visualize gr")
return fig
def user_greeting2(inLogregC,inGNBC,inM,dfData,dfLabs):
X=dfData.to_numpy(dtype=np.float64)
y=dfLabs.to_numpy(dtype=np.float64)
y=y.reshape((y.shape[1],))
#
print("X dims",X.shape)
print("y dims",y.shape)
#
#
labnos=np.unique(y)
labnos=np.int32(labnos)
kK=labnos.shape[0]
lsData=[]
lslabs=[]
for k in range(kK):
yk=y[y==labnos[k]]
datak=X[y==labnos[k],:]
lsData.append(datak)
lslabs.append(yk)
#
strTitle='Title'
fig2=visualise_gr([],[],lsData,inTitle=strTitle,th=0.001,kNum=90)
#
strTitle2='Title2'
fig3=visualise_gr([],[],lsData,inTitle=strTitle2,kNum=90)
#
fig1=visualise_gr([],[],lsData)
return fig1,fig2,fig3
def user_greeting1(inLogregC,inGNBC,inM,dfData,dfLabs):
#
print('dbg 1 in')
print(dfData)
print(dfLabs)
#
X=dfData.to_numpy(dtype=np.float64)
y=dfLabs.to_numpy(dtype=np.float64)
y=y.reshape((y.shape[1],))
#
print('dbg 1 after to_numpy')
print("X dims",X.shape)
print("y dims",y.shape)
#
labnos=np.unique(y)
labnos=np.int32(labnos)
kK=labnos.shape[0]
lsData=[]
lslabs=[]
for k in range(kK):
yk=y[y==labnos[k]]
datak=X[y==labnos[k],:]
lsData.append(datak)
lslabs.append(yk)
#
strTitle="Title1"
fig2=visualise_gr([],[],lsData,inTitle=strTitle,th=0.001,kNum=200)
#
strTitle2="Title2"
fig3=visualise_gr([],[],lsData,inTitle=strTitle2,kNum=200)
inputs1 = [ gr.Number(label='xxx C'),gr.Number(label='yyy C'),gr.Number(label='mmm'),
gr.Dataframe(row_count = (3, "dynamic"), col_count=(4,"dynamic"), label="Labeled Data", interactive=1),
gr.Dataframe(row_count = (1, "fixed"), col_count=(4,"dynamic"), label="Labels", interactive=1),
]
outputs1=[gr.Plot(),gr.Plot(),gr.Plot()]
app1 = gr.Interface(fn = user_greeting1, inputs=inputs1, outputs=outputs1, examples =[['1.0','10.0','0.001', 'data_NB.csv', 'labels_NB.csv']])
inputs2 = [ gr.Number(label='xxx C'),gr.Number(label='yyy C'),gr.Number(label='mmm'),
gr.Dataframe(row_count = (3, "dynamic"), col_count=(4,"dynamic"), label="Labeled Data", interactive=1),
gr.Dataframe(row_count = (1, "fixed"), col_count=(4,"dynamic"), label="Labels", interactive=1),
]
outputs2=[gr.Plot(),gr.Plot(),gr.Plot()]
app2 = gr.Interface(fn = user_greeting2, inputs=inputs2, outputs=outputs2,examples =[[1.0,1.0,0.001, Xhpd,yhpd]])
demo = gr.TabbedInterface([app1, app2], ["App1", "App2"])
#demo.launch(share=True)
demo.launch(share=False)
Have you searched existing issues? 🔎
Reproduction
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from copy import deepcopy
import time
import gradio as gr
plt.rcParams['figure.figsize'] = [10, 10]
plt.rcParams['figure.dpi'] = 100
Xhpd=pd.read_csv("data_NB.csv",header=None)
yhpd=pd.read_csv("labels_NB.csv",header=None)
def visualise_gr(models,names,lsData,inTitle="Data Set",kNum=200,th=0.001):
fig=plt.figure()
plt.scatter(lsData[0][:,0],lsData[0][:,1], color='red')
plt.scatter(lsData[1][:,0],lsData[1][:,1], color='blue')
plt.xticks(range(0,11))
plt.yticks(range(0,11))
plt.xlabel("X")
plt.ylabel("Y")
plt.grid()
plt.title(inTitle)
#
plt.axis('scaled')
print("visualize gr")
return fig
def user_greeting2(inLogregC,inGNBC,inM,dfData,dfLabs):
X=dfData.to_numpy(dtype=np.float64)
y=dfLabs.to_numpy(dtype=np.float64)
y=y.reshape((y.shape[1],))
#
print("X dims",X.shape)
print("y dims",y.shape)
#
#
labnos=np.unique(y)
labnos=np.int32(labnos)
kK=labnos.shape[0]
lsData=[]
lslabs=[]
for k in range(kK):
yk=y[y==labnos[k]]
datak=X[y==labnos[k],:]
lsData.append(datak)
lslabs.append(yk)
#
strTitle='Title'
fig2=visualise_gr([],[],lsData,inTitle=strTitle,th=0.001,kNum=90)
#
strTitle2='Title2'
fig3=visualise_gr([],[],lsData,inTitle=strTitle2,kNum=90)
#
fig1=visualise_gr([],[],lsData)
return fig1,fig2,fig3
def user_greeting1(inLogregC,inGNBC,inM,dfData,dfLabs):
#
print('dbg 1 in')
print(dfData)
print(dfLabs)
#
X=dfData.to_numpy(dtype=np.float64)
y=dfLabs.to_numpy(dtype=np.float64)
y=y.reshape((y.shape[1],))
#
print('dbg 1 after to_numpy')
print("X dims",X.shape)
print("y dims",y.shape)
#
labnos=np.unique(y)
labnos=np.int32(labnos)
kK=labnos.shape[0]
lsData=[]
lslabs=[]
for k in range(kK):
yk=y[y==labnos[k]]
datak=X[y==labnos[k],:]
lsData.append(datak)
lslabs.append(yk)
#
strTitle="Title1"
fig2=visualise_gr([],[],lsData,inTitle=strTitle,th=0.001,kNum=200)
#
strTitle2="Title2"
fig3=visualise_gr([],[],lsData,inTitle=strTitle2,kNum=200)
inputs1 = [ gr.Number(label='xxx C'),gr.Number(label='yyy C'),gr.Number(label='mmm'),
gr.Dataframe(row_count = (3, "dynamic"), col_count=(4,"dynamic"), label="Labeled Data", interactive=1),
gr.Dataframe(row_count = (1, "fixed"), col_count=(4,"dynamic"), label="Labels", interactive=1),
]
outputs1=[gr.Plot(),gr.Plot(),gr.Plot()]
app1 = gr.Interface(fn = user_greeting1, inputs=inputs1, outputs=outputs1, examples =[['1.0','10.0','0.001', 'data_NB.csv', 'labels_NB.csv']])
inputs2 = [ gr.Number(label='xxx C'),gr.Number(label='yyy C'),gr.Number(label='mmm'),
gr.Dataframe(row_count = (3, "dynamic"), col_count=(4,"dynamic"), label="Labeled Data", interactive=1),
gr.Dataframe(row_count = (1, "fixed"), col_count=(4,"dynamic"), label="Labels", interactive=1),
]
outputs2=[gr.Plot(),gr.Plot(),gr.Plot()]
app2 = gr.Interface(fn = user_greeting2, inputs=inputs2, outputs=outputs2,examples =[[1.0,1.0,0.001, Xhpd,yhpd]])
demo = gr.TabbedInterface([app1, app2], ["App1", "App2"])
#demo.launch(share=True)
demo.launch(share=False)
data_NB.csv
labels_NB.csv
Screenshot
No response
Logs
System Info
Severity
Blocking usage of gradio
The text was updated successfully, but these errors were encountered: