You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Traceback (most recent call last):
File "/home/user/app/app.py", line 114, in<module>
app2 = gr.Interface(fn = user_greeting2, inputs=inputs2, outputs=outputs2,examples =[[1.0,1.0,0.001, Xhpd,yhpd]])
File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 546, in __init__
self.render_examples()
File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 904, in render_examples
self.examples_handler = Examples(
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 57, in create_examples
examples_obj = Examples(
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 265, in __init__
self.dataset = components.Dataset(
File "/usr/local/lib/python3.10/site-packages/gradio/component_meta.py", line 181, in wrapper
return fn(self, **kwargs)
File "/usr/local/lib/python3.10/site-packages/gradio/components/dataset.py", line 118, in __init__
ex = component.as_example(ex)
File "/usr/local/lib/python3.10/site-packages/gradio/components/base.py", line 309, in as_example
return self.process_example(value)
File "/usr/local/lib/python3.10/site-packages/gradio/components/dataframe.py", line 507, in process_example
value_df_data = self.postprocess(value)
File "/usr/local/lib/python3.10/site-packages/gradio/components/dataframe.py", line 431, in postprocess
return DataframeData(
File "/usr/local/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for DataframeData
headers.0
Input should be a valid string [type=string_type, input_value=0, input_type=int]
For further information visit https://errors.pydantic.dev/2.10/v/string_type
headers.1
Input should be a valid string [type=string_type, input_value=1, input_type=int]
For further information visit https://errors.pydantic.dev/2.10/v/string_type
Traceback (most recent call last):
File "/home/user/app/app.py", line 114, in<module>
app2 = gr.Interface(fn = user_greeting2, inputs=inputs2, outputs=outputs2,examples =[[1.0,1.0,0.001, Xhpd,yhpd]])
File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 546, in __init__
self.render_examples()
File "/usr/local/lib/python3.10/site-packages/gradio/interface.py", line 904, in render_examples
self.examples_handler = Examples(
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 57, in create_examples
examples_obj = Examples(
File "/usr/local/lib/python3.10/site-packages/gradio/helpers.py", line 265, in __init__
self.dataset = components.Dataset(
File "/usr/local/lib/python3.10/site-packages/gradio/component_meta.py", line 181, in wrapper
return fn(self, **kwargs)
File "/usr/local/lib/python3.10/site-packages/gradio/components/dataset.py", line 118, in __init__
ex = component.as_example(ex)
File "/usr/local/lib/python3.10/site-packages/gradio/components/base.py", line 309, in as_example
return self.process_example(value)
File "/usr/local/lib/python3.10/site-packages/gradio/components/dataframe.py", line 507, in process_example
value_df_data = self.postprocess(value)
File "/usr/local/lib/python3.10/site-packages/gradio/components/dataframe.py", line 431, in postprocess
return DataframeData(
File "/usr/local/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 2 validation errors for DataframeData
headers.0
Input should be a valid string [type=string_type, input_value=0, input_type=int]
For further information visit https://errors.pydantic.dev/2.10/v/string_type
headers.1
Input should be a valid string [type=string_type, input_value=1, input_type=int]
For further information visit https://errors.pydantic.dev/2.10/v/string_type
System Info
Hugging Face
Severity
Blocking usage of gradio
The text was updated successfully, but these errors were encountered:
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,
I added an app.py file (as app.txt). This works fine on my machine with the same configuration given in the added requirements.txt file. It still doesn't work & gives a runtime error on Hugging Face
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: