Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas
|
| 2 |
+
import numpy
|
| 3 |
+
import gradio
|
| 4 |
+
import matplotlib.pyplot
|
| 5 |
+
import matplotlib.collections
|
| 6 |
+
|
| 7 |
+
data = pandas.read_csv("1-s2.0-S2352340918302014-mmc2.csv")
|
| 8 |
+
|
| 9 |
+
def how_many_designs(team: int, participant: int):
|
| 10 |
+
n = len(numpy.unique(data[(data['Team'] == team) & (data['Participant'] == participant)]['Design']))
|
| 11 |
+
return gradio.Slider.update(1, n, step=1)
|
| 12 |
+
|
| 13 |
+
def print_design(team: int, participant: int, design: int):
|
| 14 |
+
df = data[(data['Team'] == 1) & (data['Participant'] == 1) & (data['Design'] == design)]
|
| 15 |
+
nodes = df[df['Component'] > 0]
|
| 16 |
+
edges = df[df['Component'] < 0]
|
| 17 |
+
e1 = [int(x) for x in edges['Var1'].values]
|
| 18 |
+
e2 = [int(x) for x in edges['Var2'].values]
|
| 19 |
+
all_info = [e1, e2, [0]*len(e1)]
|
| 20 |
+
idx = numpy.array(all_info).transpose().flatten()
|
| 21 |
+
x = [None if i == 0 else nodes[nodes['Component'] == i]['Var1'].values[0] for i in idx]
|
| 22 |
+
y = [None if i == 0 else nodes[nodes['Component'] == i]['Var2'].values[0] for i in idx]
|
| 23 |
+
fig = matplotlib.pyplot.figure()
|
| 24 |
+
matplotlib.pyplot.plot(x, y)
|
| 25 |
+
matplotlib.pyplot.plot(nodes['Var1'].values, nodes['Var2'].values, linestyle='none', marker='o', label="")
|
| 26 |
+
|
| 27 |
+
matplotlib.pyplot.axis('equal')
|
| 28 |
+
matplotlib.pyplot.xlim([-6.0, 6.0])
|
| 29 |
+
matplotlib.pyplot.ylim([-3.0, 5.0])
|
| 30 |
+
return fig
|
| 31 |
+
|
| 32 |
+
with gradio.Blocks() as demo:
|
| 33 |
+
with gradio.Row():
|
| 34 |
+
with gradio.Column():
|
| 35 |
+
team = gradio.Dropdown(choices=[str(i) for i in range(1,17)], value="1")
|
| 36 |
+
participant = gradio.Dropdown(choices=[str(i) for i in range(1,4)], value="1")
|
| 37 |
+
design = gradio.Slider(1, 100, step=1, value=1)
|
| 38 |
+
with gradio.Column():
|
| 39 |
+
output = gradio.Plot()
|
| 40 |
+
|
| 41 |
+
team.change(fn=how_many_designs, inputs=[team, participant], outputs=[design])
|
| 42 |
+
participant.change(fn=how_many_designs, inputs=[team, participant], outputs=[design])
|
| 43 |
+
|
| 44 |
+
participant.change(fn=print_design, inputs=[team, participant, design], outputs=[output])
|
| 45 |
+
team.change(fn=print_design, inputs=[team, participant, design], outputs=[output])
|
| 46 |
+
design.change(fn=print_design, inputs=[team, participant, design], outputs=[output])
|
| 47 |
+
|
| 48 |
+
demo.launch(debug=True)
|