Spaces:
Runtime error
Runtime error
File size: 2,117 Bytes
1b1f8bd 2ff0f36 1b1f8bd |
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 37 38 39 40 41 42 43 44 45 46 47 48 |
import pandas
import numpy
import gradio
import matplotlib.pyplot
import matplotlib.collections
data = pandas.read_csv("1-s2.0-S2352340918302014-mmc2.csv")
def how_many_designs(team: int, participant: int):
n = len(numpy.unique(data[(data['Team'] == team) & (data['Participant'] == participant)]['Design']))
return gradio.Slider.update(1, n, step=1)
def print_design(team: int, participant: int, design: int):
df = data[(data['Team'] == 1) & (data['Participant'] == 1) & (data['Design'] == design)]
nodes = df[df['Component'] > 0]
edges = df[df['Component'] < 0]
e1 = [int(x) for x in edges['Var1'].values]
e2 = [int(x) for x in edges['Var2'].values]
all_info = [e1, e2, [0]*len(e1)]
idx = numpy.array(all_info).transpose().flatten()
x = [None if i == 0 else nodes[nodes['Component'] == i]['Var1'].values[0] for i in idx]
y = [None if i == 0 else nodes[nodes['Component'] == i]['Var2'].values[0] for i in idx]
fig = matplotlib.pyplot.figure()
matplotlib.pyplot.plot(x, y)
matplotlib.pyplot.plot(nodes['Var1'].values, nodes['Var2'].values, linestyle='none', marker='o', label="")
matplotlib.pyplot.axis('equal')
matplotlib.pyplot.xlim([-6.0, 6.0])
matplotlib.pyplot.ylim([-3.0, 5.0])
return fig
with gradio.Blocks() as demo:
with gradio.Row():
with gradio.Column():
team = gradio.Dropdown(choices=[str(i) for i in range(1,17)], value="1")
participant = gradio.Dropdown(choices=[str(i) for i in range(1,4)], value="1")
design = gradio.Slider(1, 100, step=1, value=1)
with gradio.Column():
output = gradio.Plot(value=print_design(1, 1, 1))
team.change(fn=how_many_designs, inputs=[team, participant], outputs=[design])
participant.change(fn=how_many_designs, inputs=[team, participant], outputs=[design])
participant.change(fn=print_design, inputs=[team, participant, design], outputs=[output])
team.change(fn=print_design, inputs=[team, participant, design], outputs=[output])
design.change(fn=print_design, inputs=[team, participant, design], outputs=[output])
demo.launch(debug=True) |