pgleeson commited on
Commit
76b7f87
·
1 Parent(s): 87d496e

Test some ideas

Browse files
Files changed (10) hide show
  1. Dockerfile +27 -0
  2. README.md +10 -6
  3. app.py +136 -0
  4. build.sh +10 -0
  5. load.py +127 -0
  6. packages.txt +3 -0
  7. position_buffer.txt +0 -0
  8. rebuild.sh +2 -0
  9. requirements.txt +4 -0
  10. run.sh +9 -0
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11
2
+
3
+ WORKDIR /app
4
+
5
+ COPY ./requirements.txt /app/requirements.txt
6
+ COPY ./packages.txt /app/packages.txt
7
+
8
+ RUN apt-get update && xargs -r -a /app/packages.txt apt-get install -y && rm -rf /var/lib/apt/lists/*
9
+ RUN pip3 install --no-cache-dir -r /app/requirements.txt
10
+
11
+ # User
12
+ RUN useradd -m -u 1000 user
13
+ USER user
14
+ ENV HOME /home/user
15
+ ENV PATH $HOME/.local/bin:$PATH
16
+
17
+ WORKDIR $HOME
18
+ RUN mkdir app
19
+ WORKDIR $HOME/app
20
+ COPY . $HOME/app
21
+
22
+ EXPOSE 8501
23
+ CMD streamlit run app.py \
24
+ --server.headless true \
25
+ --server.enableCORS false \
26
+ --server.enableXsrfProtection false \
27
+ --server.fileWatcherType none
README.md CHANGED
@@ -1,11 +1,15 @@
1
  ---
2
- title: TestSibernetic
3
- emoji: 🦀
4
- colorFrom: indigo
5
- colorTo: gray
6
  sdk: docker
 
7
  pinned: false
8
- license: mit
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
+ title: Test Sibernetic...
3
+ emoji: 🐢
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: docker
7
+ app_port: 8501
8
  pinned: false
 
9
  ---
10
 
11
+ ## 🧠 Streamlit Docker Template 🔎
12
+
13
+ Streamlit Docker Template is a template for creating a Streamlit app with Docker and Hugging Face Spaces.
14
+
15
+ Code from https://docs.streamlit.io/library/get-started/create-an-app
app.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import stpyvista.utils
3
+
4
+ if "IS_XVFB_RUNNING" not in st.session_state:
5
+ stpyvista.utils.start_xvfb()
6
+ st.session_state.IS_XVFB_RUNNING = True
7
+
8
+ st.title("Sibernetic simple example")
9
+
10
+ import pyvista as pv
11
+ import numpy as np
12
+
13
+ import time
14
+
15
+ points = []
16
+ types = []
17
+
18
+ file = "position_buffer.txt"
19
+
20
+ colours = {1.1: "lightblue", 2.1: "green", 2.2: "turquoise", 3: "#eeeeee"}
21
+ colours = {1.1: "blue", 2.2: "turquoise"}
22
+
23
+ line_count = 0
24
+ pcount = 0
25
+
26
+ all_points = []
27
+ all_point_types = []
28
+
29
+ time_count = 0
30
+
31
+ logStep = None
32
+
33
+ include_boundary = False
34
+
35
+ for l in open(file):
36
+ ws = l.split()
37
+ #print(ws)
38
+ if line_count == 6:
39
+ numOfElasticP = int(ws[0])
40
+ if line_count == 7:
41
+ numOfLiquidP = int(ws[0])
42
+ if line_count == 8:
43
+ numOfBoundaryP = int(ws[0])
44
+ if line_count == 9:
45
+ timeStep = float(ws[0])
46
+ if line_count == 10:
47
+ logStep = int(ws[0])
48
+
49
+ if len(ws) == 4:
50
+ type = float(ws[3])
51
+
52
+ if not (type == 3 and not include_boundary):
53
+ points.append([float(ws[0]), float(ws[1]), float(ws[2])])
54
+ types.append(type)
55
+
56
+ if logStep is not None:
57
+ pcount+=1
58
+
59
+ if pcount==numOfBoundaryP+numOfElasticP+numOfLiquidP:
60
+ print('End of one batch of %i added, %i total points at line %i, time: %i'%(len(points),pcount, line_count, time_count))
61
+ all_points.append(points)
62
+ all_point_types.append(types)
63
+
64
+ points = []
65
+ types=[]
66
+ pcount = 0
67
+ numOfBoundaryP=0
68
+
69
+ time_count+=1
70
+
71
+ line_count += 1
72
+
73
+ #all_points_np = np.array(all_points)
74
+
75
+ print(f"Loaded positions with %i elastic, %i liquid and %i boundary points (%i total), %i lines"%(numOfElasticP,numOfLiquidP, numOfBoundaryP,numOfElasticP+numOfLiquidP+numOfBoundaryP, line_count))
76
+ print("Num of time points found: %i"%len(all_points))
77
+
78
+ pl = pv.Plotter(window_size=[800,600])
79
+ pl.set_background("lightgrey")
80
+
81
+ pl.camera.position = (300, 100, -100.0)
82
+ pl.camera.focal_point = (50,0,100)
83
+ pl.camera.up = (0.0, 1.0, 0.0)
84
+ #pl.add_axes_at_origin(labels_off=False)
85
+ #pl.add_mesh(pv.Cube(center=(50,0,50)))
86
+
87
+ last_mesh = None
88
+
89
+ def create_mesh(step):
90
+
91
+ step_count = step
92
+ value=step_count
93
+ global last_mesh
94
+ index = int(value)
95
+
96
+ print('Changing to time point: %s (%s) '%(index,value))
97
+ curr_points = all_points[index]
98
+ curr_types = all_point_types[index]
99
+ if last_mesh is None:
100
+
101
+ print('Adding mesh...')
102
+ last_mesh = pv.PolyData(curr_points)
103
+ last_mesh["types"] = curr_types
104
+ print(last_mesh)
105
+ mesh2 = pv.Cube(center=(0,0,0))
106
+ pl.add_mesh(mesh2)
107
+
108
+ last_actor = pl.add_mesh(
109
+ last_mesh,
110
+ render_points_as_spheres=True,
111
+ cmap=[c for c in colours.values()],
112
+ point_size=3,
113
+ )
114
+ else:
115
+
116
+ print('Updating mesh...')
117
+ last_mesh.points = curr_points
118
+
119
+ #pl.render()
120
+
121
+ time.sleep(0.1)
122
+
123
+ return
124
+
125
+ create_mesh(0)
126
+
127
+ max_time = len(all_points)-1
128
+ #pl.add_slider_widget(create_mesh, rng=[0,max_time], value=max_time, title='Time point')
129
+ #pl.add_timer_event( max_steps=len(all_points), duration=200, callback=create_mesh)
130
+
131
+ print('Ready...')
132
+
133
+ from stpyvista import stpyvista as spv
134
+ ## Send to streamlit
135
+ spv(pl, key="pv_cube2")
136
+
build.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Set the platform flag if we're on ARM
2
+ arch=$(uname -m)
3
+ if [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then
4
+ platform_flag="--platform linux/amd64"
5
+ else
6
+ platform_flag=""
7
+ fi
8
+
9
+ docker build $platform_flag -t testdox -f Dockerfile .
10
+
load.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pyvista as pv
2
+
3
+ import sys
4
+ import numpy as np
5
+
6
+ import time
7
+
8
+ points = []
9
+
10
+ types = []
11
+
12
+ file = "pressure_buffer.txt"
13
+ file = "position_buffer.txt"
14
+ if len(sys.argv) == 2:
15
+ file = sys.argv[1]
16
+
17
+ colours = {1.1: "lightblue", 2.1: "green", 2.2: "turquoise", 3: "#eeeeee"}
18
+ colours = {1.1: "blue", 2.2: "turquoise"}
19
+
20
+ line_count = 0
21
+ pcount = 0
22
+
23
+ all_points = []
24
+ all_point_types = []
25
+
26
+ time_count = 0
27
+
28
+ logStep = None
29
+
30
+ include_boundary = False
31
+
32
+ for l in open(file):
33
+ ws = l.split()
34
+ #print(ws)
35
+ if line_count == 6:
36
+ numOfElasticP = int(ws[0])
37
+ if line_count == 7:
38
+ numOfLiquidP = int(ws[0])
39
+ if line_count == 8:
40
+ numOfBoundaryP = int(ws[0])
41
+ if line_count == 9:
42
+ timeStep = float(ws[0])
43
+ if line_count == 10:
44
+ logStep = int(ws[0])
45
+
46
+ if len(ws) == 4:
47
+ type = float(ws[3])
48
+
49
+ if not (type == 3 and not include_boundary):
50
+ points.append([float(ws[0]), float(ws[1]), float(ws[2])])
51
+ types.append(type)
52
+
53
+ if logStep is not None:
54
+ pcount+=1
55
+
56
+ if pcount==numOfBoundaryP+numOfElasticP+numOfLiquidP:
57
+ print('End of one batch of %i added, %i total points at line %i, time: %i'%(len(points),pcount, line_count, time_count))
58
+ all_points.append(points)
59
+ all_point_types.append(types)
60
+
61
+ points = []
62
+ types=[]
63
+ pcount = 0
64
+ numOfBoundaryP=0
65
+
66
+ time_count+=1
67
+
68
+
69
+ line_count += 1
70
+
71
+ #all_points_np = np.array(all_points)
72
+
73
+ print(f"Loaded positions with %i elastic, %i liquid and %i boundary points (%i total), %i lines"%(numOfElasticP,numOfLiquidP, numOfBoundaryP,numOfElasticP+numOfLiquidP+numOfBoundaryP, line_count))
74
+
75
+ print("Num of time points found: %i"%len(all_points))
76
+
77
+ pl = pv.Plotter()
78
+ pl.set_background("lightgrey")
79
+
80
+ pl.camera.position = (300, 100, -100.0)
81
+ pl.camera.focal_point = (50,0,100)
82
+ pl.camera.up = (0.0, 1.0, 0.0)
83
+ #pl.add_axes_at_origin(labels_off=False)
84
+ #pl.add_mesh(pv.Cube(center=(50,0,50)))
85
+
86
+ last_mesh = None
87
+
88
+
89
+ def create_mesh(step):
90
+ step_count = step
91
+ value=step_count
92
+ global last_mesh
93
+ index = int(value)
94
+
95
+
96
+ print('Changing to time point: %s (%s) '%(index,value))
97
+ curr_points = all_points[index]
98
+ curr_types = all_point_types[index]
99
+ if last_mesh is None:
100
+
101
+ last_mesh = pv.PolyData(curr_points)
102
+ last_mesh["types"] = curr_types
103
+ print(last_mesh)
104
+
105
+ last_actor = pl.add_mesh(
106
+ last_mesh,
107
+ render_points_as_spheres=True,
108
+ cmap=[c for c in colours.values()],
109
+ point_size=3,
110
+ )
111
+ else:
112
+ last_mesh.points = curr_points
113
+
114
+ pl.render()
115
+
116
+ time.sleep(0.01)
117
+
118
+ return
119
+
120
+ create_mesh(0)
121
+
122
+ max_time = len(all_points)-1
123
+ pl.add_slider_widget(create_mesh, rng=[0,max_time], value=max_time, title='Time point')
124
+ pl.add_timer_event( max_steps=len(all_points), duration=200, callback=create_mesh)
125
+
126
+ pl.show()
127
+
packages.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ procps
2
+ libgl1-mesa-glx
3
+ xvfb
position_buffer.txt ADDED
The diff for this file is too large to render. See raw diff
 
rebuild.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ docker build --platform linux/amd64 -t testdox -f Dockerfile --no-cache .
2
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pyneuroml
3
+ pyvista
4
+ stpyvista
run.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Set the platform flag if we're on ARM
2
+ arch=$(uname -m)
3
+ if [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then
4
+ platform_flag="--platform linux/amd64"
5
+ else
6
+ platform_flag=""
7
+ fi
8
+
9
+ docker run -it -p 8501:8501 $platform_flag testdox