Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
web-ros3rag
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
web-ros3rag
Commits
52521186
Commit
52521186
authored
2 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
enable dockerized, configurable build
parent
fb52508d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Dockerfile
+8
-0
8 additions, 0 deletions
Dockerfile
config.yaml
+6
-0
6 additions, 0 deletions
config.yaml
main.py
+28
-11
28 additions, 11 deletions
main.py
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
with
43 additions
and
11 deletions
Dockerfile
0 → 100644
+
8
−
0
View file @
52521186
FROM
python:3.9
COPY
requirements.txt /requirements.txt
RUN
pip
install
-r
requirements.txt
COPY
main.py utils.py cgv_connector_pb2.py /app/
COPY
config/ /app/config
WORKDIR
"/app"
ENTRYPOINT
"python" "main.py"
This diff is collapsed.
Click to expand it.
config.yaml
0 → 100644
+
6
−
0
View file @
52521186
# enter path to ros3rag/ros3rag.placeB/images
# image_directory: null
image_directory
:
/data/git/jastadd/ros3rag/ros3rag.placeB/images
# enter IP or hostname of mqtt broker
mqtt_server
:
"
192.168.0.122"
This diff is collapsed.
Click to expand it.
main.py
+
28
−
11
View file @
52521186
...
...
@@ -5,6 +5,8 @@ import threading
import
time
import
base64
import
flask
import
yaml
import
sys
import
dash
from
dash
import
dcc
...
...
@@ -17,15 +19,11 @@ from google.protobuf import json_format
import
cgv_connector_pb2
import
utils
CONFIG_FILENAME
=
'
config.yaml
'
config
=
{}
external_stylesheets
=
[
'
https://codepen.io/chriddyp/pen/bWLwgP.css
'
]
fixed_svg_filename
=
"
ros3rag/ros3rag.placeB/images/2022-05-04T10-19-30-9155.svg
"
fixed_svg_filename
=
"
2022-05-04T10-19-30-9155.svg
"
# fixed_svg_filename = ""
image_directory
=
'
/data/git/jastadd/ros3rag/ros3rag.placeB/images/
'
static_image_route
=
'
/static/
'
MQTT_SERVER
=
'
192.168.0.122
'
# MQTT_SERVER = 'localhost'
mqttc
=
mqtt
.
Client
()
# mqtt client connected?
...
...
@@ -300,7 +298,7 @@ app.layout = html.Div([
html
.
P
(
id
=
'
model-b-svg-name
'
,
style
=
{
"
margin-left
"
:
"
15px
"
}),
],
className
=
'
row
'
,
style
=
dict
(
display
=
'
flex
'
)),
html
.
Div
([
html
.
Img
(
id
=
'
model-b-svg-img
'
,
src
=
"
/static/{}
"
.
format
(
fi
x
ed
_
svg
_filename
))
html
.
Img
(
id
=
'
model-b-svg-img
'
,
src
=
"
/static/{}
"
.
format
(
"
unde
fi
n
ed
.
svg
"
))
],
style
=
dict
(
position
=
'
fixed
'
,
overflow
=
'
scroll
'
,
width
=
'
100%
'
)),
# html.Img(src="data:image/svg;base64,{}".format(base64.b64encode(open(fixed_svg_filename, 'rb').read()).decode()))
],
style
=
tab_style
,
selected_style
=
tab_style
)
# Tab "SVG Model B"
...
...
@@ -558,6 +556,7 @@ def update_svg_name(name):
@app.server.route
(
'
{}<image_path>.svg
'
.
format
(
static_image_route
))
def
serve_image
(
image_path
):
image_name
=
'
{}.svg
'
.
format
(
image_path
)
image_directory
=
config
[
'
image_directory
'
]
print
(
'
{}/{}
'
.
format
(
image_directory
,
image_name
))
# if image_name not in list_of_images:
# raise Exception('"{}" is excluded from the allowed static files'.format(image_path))
...
...
@@ -566,7 +565,7 @@ def serve_image(image_path):
def
on_mqtt_connect
(
_client
,
_userdata
,
_flags
,
_rc
,
_properties
=
None
):
# Callback for mqtt client when connected
print
(
f
'
\n
Connected to
{
MQTT_SERVER
}
at
{
datetime
.
datetime
.
now
().
isoformat
()
}
'
)
print
(
f
'
\n
Connected to
{
config
[
"
mqtt_server
"
]
}
at
{
datetime
.
datetime
.
now
().
isoformat
()
}
'
)
ready_event
.
set
()
mqttc
.
subscribe
(
topic
=
'
#
'
)
threading
.
Thread
(
target
=
publish_test_message
).
start
()
...
...
@@ -610,12 +609,30 @@ def publish_test_message():
if
__name__
==
'
__main__
'
:
print
(
'
Starting web-ros3rag
'
)
try
:
with
open
(
CONFIG_FILENAME
,
'
r
'
)
as
fd
:
config
=
yaml
.
safe_load
(
fd
)
except
FileNotFoundError
as
e
:
print
(
f
'
Could not open
{
CONFIG_FILENAME
}
. Aborting.
'
)
sys
.
exit
(
1
)
if
not
config
[
'
image_directory
'
]:
print
(
'
image_directory not specified. Aborting.
'
)
sys
.
exit
(
1
)
dockerized
=
config
.
get
(
'
docker
'
)
mqttc
.
on_connect
=
on_mqtt_connect
mqttc
.
on_disconnect
=
on_mqtt_disconnect
mqttc
.
on_message
=
on_mqtt_message
mqttc
.
reconnect_delay_set
(
max_delay
=
2
)
mqttc
.
connect_async
(
MQTT_SERVER
)
mqttc
.
connect_async
(
config
[
'
mqtt_server
'
]
)
mqttc
.
loop_start
()
if
not
ready_event
.
wait
(
2.0
):
# wait 2 seconds
print
(
'
Could not connect to mqtt in time!
'
)
app
.
run_server
(
debug
=
True
)
print
(
f
'
Could not connect to mqtt at
{
config
[
"
mqtt_server
"
]
}
in time!
'
)
if
dockerized
:
app
.
run_server
(
host
=
'
0.0.0.0
'
,
port
=
8050
)
else
:
app
.
run_server
(
debug
=
True
,
port
=
8050
)
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
52521186
...
...
@@ -2,3 +2,4 @@ paho-mqtt~=1.6.1
dash
~=2.3.1
visdcc
~=0.0.50
protobuf
~=3.20.0
pyyaml
~=6.0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment