webdisplay 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- webdisplay-0.1.0/LICENSE +201 -0
- webdisplay-0.1.0/PKG-INFO +11 -0
- webdisplay-0.1.0/README.rst +45 -0
- webdisplay-0.1.0/pyproject.toml +26 -0
- webdisplay-0.1.0/setup.cfg +4 -0
- webdisplay-0.1.0/src/webdisplay/__init__.py +15 -0
- webdisplay-0.1.0/src/webdisplay/client.py +121 -0
- webdisplay-0.1.0/src/webdisplay/server.py +122 -0
- webdisplay-0.1.0/src/webdisplay/static/index.html +515 -0
- webdisplay-0.1.0/src/webdisplay.egg-info/PKG-INFO +11 -0
- webdisplay-0.1.0/src/webdisplay.egg-info/SOURCES.txt +13 -0
- webdisplay-0.1.0/src/webdisplay.egg-info/dependency_links.txt +1 -0
- webdisplay-0.1.0/src/webdisplay.egg-info/entry_points.txt +2 -0
- webdisplay-0.1.0/src/webdisplay.egg-info/requires.txt +1 -0
- webdisplay-0.1.0/src/webdisplay.egg-info/top_level.txt +1 -0
webdisplay-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webdisplay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Un toolkit pour vite coder un modèle pytorch d'IA utilisant MLflow
|
|
5
|
+
Author-email: Jean-François Lecomte <zwergon@free.fr>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: websockets
|
|
11
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
webdisplay
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
Small remote display of images. The server is implemented in Python and the client is a web page.
|
|
5
|
+
The server can be used to display images from a Python program on a web page.
|
|
6
|
+
Its main use is for debugging and monitoring purposes, but it can also be used for other applications.
|
|
7
|
+
The same philosophy as X11 but for the web.
|
|
8
|
+
|
|
9
|
+
Installation
|
|
10
|
+
------------
|
|
11
|
+
|
|
12
|
+
.. code-block:: bash
|
|
13
|
+
|
|
14
|
+
pip install webdisplay
|
|
15
|
+
|
|
16
|
+
Server Usage
|
|
17
|
+
------------
|
|
18
|
+
|
|
19
|
+
.. code-block:: bash
|
|
20
|
+
|
|
21
|
+
webdisplay-server --port 8765 # default port is 8765
|
|
22
|
+
|
|
23
|
+
This will start a server on port 8765 and open a web browser connected to this server. You can change the port if needed.
|
|
24
|
+
There is also a `--no-browser` option to prevent the browser from opening automatically.
|
|
25
|
+
This is useful if you want to send images from a remote machine to your local machine.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
The client produce a figure, use the webdisplay client to send it to the server then the server will display it on the web page.
|
|
29
|
+
You can send multiple figures and they will be displayed as a list of pictures in the web page.
|
|
30
|
+
|
|
31
|
+
Client Usage
|
|
32
|
+
------------
|
|
33
|
+
|
|
34
|
+
.. code-block:: python
|
|
35
|
+
|
|
36
|
+
import webdisplay
|
|
37
|
+
import matplotlib.pyplot as plt
|
|
38
|
+
|
|
39
|
+
# should be called only once in the program, before any other webdisplay function is called
|
|
40
|
+
webdisplay.connect("ws://localhost:8765/send") # most likely the default address, but you can change it if needed
|
|
41
|
+
|
|
42
|
+
fig, ax = plt.subplots()
|
|
43
|
+
ax.plot([1, 4, 2, 8, 5])
|
|
44
|
+
webdisplay.show_figure(fig)
|
|
45
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
requires = ["setuptools>=61.0"]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
description = "Un toolkit pour vite coder un modèle pytorch d'IA utilisant MLflow"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
name = "webdisplay"
|
|
9
|
+
dependencies = ["websockets"]
|
|
10
|
+
|
|
11
|
+
authors = [{ name = "Jean-François Lecomte", email = "zwergon@free.fr" }]
|
|
12
|
+
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
requires-python = ">=3.10"
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
where = ["src"]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
webdisplay_server = "webdisplay.server:run"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
[tool.setuptools.package-data]
|
|
26
|
+
webdisplay = ["*.html"]
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""
|
|
2
|
+
webdisplay.py — Module côté machine distante
|
|
3
|
+
Copiez ce fichier à côté de vos scripts Python.
|
|
4
|
+
|
|
5
|
+
Dépendances : pip install websockets pillow
|
|
6
|
+
(matplotlib est optionnel, uniquement si vous utilisez show_figure)
|
|
7
|
+
|
|
8
|
+
Usage rapide :
|
|
9
|
+
import webdisplay
|
|
10
|
+
webdisplay.connect("ws://localhost:8765/send") # une seule fois
|
|
11
|
+
|
|
12
|
+
# Depuis matplotlib
|
|
13
|
+
webdisplay.show_figure(fig)
|
|
14
|
+
|
|
15
|
+
# Depuis PIL / Pillow
|
|
16
|
+
webdisplay.show_image(pil_img)
|
|
17
|
+
|
|
18
|
+
# Depuis des bytes PNG bruts
|
|
19
|
+
webdisplay.show_png(png_bytes)
|
|
20
|
+
|
|
21
|
+
# Fermer proprement en fin de script
|
|
22
|
+
webdisplay.close()
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import asyncio
|
|
26
|
+
import io
|
|
27
|
+
import threading
|
|
28
|
+
import base64
|
|
29
|
+
import json
|
|
30
|
+
import websockets
|
|
31
|
+
|
|
32
|
+
# ── état interne ──────────────────────────────────────────────────────────────
|
|
33
|
+
_loop: asyncio.AbstractEventLoop | None = None
|
|
34
|
+
_thread: threading.Thread | None = None
|
|
35
|
+
_ws = None
|
|
36
|
+
_uri: str = "ws://localhost:8765/send"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# ── démarrage de la boucle asyncio dans un thread dédié ──────────────────────
|
|
40
|
+
|
|
41
|
+
def connect(uri: str = "ws://localhost:8765/send"):
|
|
42
|
+
"""Ouvre la connexion WebSocket vers le relay. Appel optionnel :
|
|
43
|
+
si vous appelez show_* sans avoir appelé connect(), la connexion
|
|
44
|
+
s'établit automatiquement avec l'URI par défaut."""
|
|
45
|
+
global _uri
|
|
46
|
+
_uri = uri
|
|
47
|
+
_ensure_started()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def close():
|
|
51
|
+
"""Ferme proprement la connexion."""
|
|
52
|
+
global _ws, _loop
|
|
53
|
+
if _ws and _loop:
|
|
54
|
+
asyncio.run_coroutine_threadsafe(_ws.close(), _loop)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ── API publique ──────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
def show_figure(fig, title: str = "", dpi: int = 150, fmt: str = "png"):
|
|
60
|
+
"""Envoie une figure matplotlib.
|
|
61
|
+
Exemple :
|
|
62
|
+
fig, ax = plt.subplots()
|
|
63
|
+
ax.plot([1,2,3])
|
|
64
|
+
webdisplay.show_figure(fig)
|
|
65
|
+
"""
|
|
66
|
+
buf = io.BytesIO()
|
|
67
|
+
fig.savefig(buf, format=fmt, dpi=dpi, bbox_inches="tight")
|
|
68
|
+
buf.seek(0)
|
|
69
|
+
show_png(buf.read(), title=title)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def show_image(pil_img, title: str = "", fmt: str = "PNG"):
|
|
73
|
+
"""Envoie un objet PIL.Image.
|
|
74
|
+
Exemple :
|
|
75
|
+
from PIL import Image
|
|
76
|
+
img = Image.open("photo.jpg")
|
|
77
|
+
webdisplay.show_image(img)
|
|
78
|
+
"""
|
|
79
|
+
buf = io.BytesIO()
|
|
80
|
+
pil_img.save(buf, format=fmt)
|
|
81
|
+
buf.seek(0)
|
|
82
|
+
show_png(buf.read(), title=title)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def show_png(png_bytes: bytes, title: str = ""):
|
|
86
|
+
"""Envoie des bytes PNG bruts."""
|
|
87
|
+
_ensure_started()
|
|
88
|
+
b64 = base64.b64encode(png_bytes).decode()
|
|
89
|
+
payload = json.dumps({"title": title, "data": b64})
|
|
90
|
+
future = asyncio.run_coroutine_threadsafe(_send(payload), _loop)
|
|
91
|
+
future.result(timeout=10) # bloquant côté script, non bloquant côté relay
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ── internals ─────────────────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
def _ensure_started():
|
|
97
|
+
global _loop, _thread
|
|
98
|
+
if _loop is None:
|
|
99
|
+
_loop = asyncio.new_event_loop()
|
|
100
|
+
_thread = threading.Thread(target=_loop.run_forever, daemon=True)
|
|
101
|
+
_thread.start()
|
|
102
|
+
# connexion initiale
|
|
103
|
+
future = asyncio.run_coroutine_threadsafe(_connect(), _loop)
|
|
104
|
+
future.result(timeout=10)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
async def _connect():
|
|
108
|
+
global _ws
|
|
109
|
+
_ws = await websockets.connect(_uri)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def _send(payload: str):
|
|
113
|
+
global _ws
|
|
114
|
+
if _ws is None:
|
|
115
|
+
await _connect()
|
|
116
|
+
try:
|
|
117
|
+
await _ws.send(payload)
|
|
118
|
+
except (websockets.exceptions.ConnectionClosed, Exception):
|
|
119
|
+
# Reconnexion automatique si la connexion a été perdue
|
|
120
|
+
await _connect()
|
|
121
|
+
await _ws.send(payload)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import pathlib
|
|
3
|
+
import time
|
|
4
|
+
import asyncio
|
|
5
|
+
import logging
|
|
6
|
+
import threading
|
|
7
|
+
import websockets
|
|
8
|
+
import webbrowser
|
|
9
|
+
|
|
10
|
+
from websockets.asyncio.server import ServerConnection
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
|
|
14
|
+
log = logging.getLogger("relay")
|
|
15
|
+
|
|
16
|
+
# Ensemble des clients navigateur connectés
|
|
17
|
+
browsers: set[ServerConnection] = set()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def _handler(ws: ServerConnection):
|
|
21
|
+
path = ws.request.path if hasattr(
|
|
22
|
+
ws, "request") else getattr(ws, "path", "/")
|
|
23
|
+
|
|
24
|
+
if path == "/send":
|
|
25
|
+
# Connexion depuis Python distant
|
|
26
|
+
log.info("Producteur connecté depuis %s", ws.remote_address)
|
|
27
|
+
try:
|
|
28
|
+
async for message in ws:
|
|
29
|
+
if browsers:
|
|
30
|
+
# Diffuse à tous les navigateurs connectés
|
|
31
|
+
await asyncio.gather(
|
|
32
|
+
*[b.send(message) for b in browsers],
|
|
33
|
+
return_exceptions=True,
|
|
34
|
+
)
|
|
35
|
+
log.info(
|
|
36
|
+
"Image diffusée à %d navigateur(s) (%d octets)",
|
|
37
|
+
len(browsers),
|
|
38
|
+
len(message) if isinstance(
|
|
39
|
+
message, (bytes, str)) else 0,
|
|
40
|
+
)
|
|
41
|
+
else:
|
|
42
|
+
log.warning("Aucun navigateur connecté, image ignorée")
|
|
43
|
+
except websockets.exceptions.ConnectionClosed:
|
|
44
|
+
pass
|
|
45
|
+
log.info("Producteur déconnecté")
|
|
46
|
+
|
|
47
|
+
else:
|
|
48
|
+
# Connexion depuis le navigateur
|
|
49
|
+
browsers.add(ws)
|
|
50
|
+
log.info("Navigateur connecté (%d au total)", len(browsers))
|
|
51
|
+
try:
|
|
52
|
+
await ws.wait_closed()
|
|
53
|
+
finally:
|
|
54
|
+
browsers.discard(ws)
|
|
55
|
+
log.info("Navigateur déconnecté (%d restants)", len(browsers))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def _relay(port: int):
|
|
59
|
+
async with websockets.serve(_handler, "0.0.0.0", port):
|
|
60
|
+
log.info("Relay démarré sur ws://localhost:%d", port)
|
|
61
|
+
await asyncio.Future()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
HERE = pathlib.Path(__file__).parent.resolve()
|
|
65
|
+
HTML_FILE = HERE / "static" / "index.html"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _open_browser(host: str, port: int, delay: float = 0.8):
|
|
69
|
+
"""Ouvre index.html après un court délai (le temps que le relay démarre)."""
|
|
70
|
+
time.sleep(delay)
|
|
71
|
+
|
|
72
|
+
html_uri = HTML_FILE.as_uri()
|
|
73
|
+
|
|
74
|
+
# On injecte l'URL WebSocket correcte dans la query-string si besoin,
|
|
75
|
+
# mais index.html lit déjà ws://localhost:8765/view par défaut.
|
|
76
|
+
# Si le port est différent, on passe par un fichier HTML temporaire
|
|
77
|
+
# avec l'URL pré-remplie.
|
|
78
|
+
if host != 'localhost' or port != 8765:
|
|
79
|
+
import tempfile
|
|
80
|
+
import shutil
|
|
81
|
+
content = HTML_FILE.read_text(encoding="utf-8")
|
|
82
|
+
content = content.replace(
|
|
83
|
+
"ws://localhost:8765/view",
|
|
84
|
+
f"ws://{host}:{port}/view",
|
|
85
|
+
)
|
|
86
|
+
tmp = pathlib.Path(tempfile.mktemp(suffix=".html"))
|
|
87
|
+
tmp.write_text(content, encoding="utf-8")
|
|
88
|
+
html_uri = tmp.as_uri()
|
|
89
|
+
|
|
90
|
+
log.info("Ouverture du navigateur : %s", html_uri)
|
|
91
|
+
webbrowser.open(html_uri)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def start(host: str = 'localhost', port: int = 8765, open_browser: bool = True):
|
|
95
|
+
"""Lance le relay et bloque jusqu'à Ctrl+C."""
|
|
96
|
+
if open_browser:
|
|
97
|
+
t = threading.Thread(target=_open_browser,
|
|
98
|
+
args=(host, port,), daemon=True)
|
|
99
|
+
t.start()
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
asyncio.run(_relay(port))
|
|
103
|
+
except KeyboardInterrupt:
|
|
104
|
+
log.info("Arrêt.")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def run():
|
|
108
|
+
parser = argparse.ArgumentParser(
|
|
109
|
+
description="Lance le relay WebDisplay et ouvre le navigateur.")
|
|
110
|
+
parser.add_argument("--host", type=str, default='localhost',
|
|
111
|
+
help="Host WebSocket (défaut : localhost)")
|
|
112
|
+
parser.add_argument("--port", type=int, default=8765,
|
|
113
|
+
help="Port WebSocket (défaut : 8765)")
|
|
114
|
+
parser.add_argument("--no-browser", action="store_true",
|
|
115
|
+
help="Ne pas ouvrir le navigateur")
|
|
116
|
+
args = parser.parse_args()
|
|
117
|
+
|
|
118
|
+
start(host=args.host, port=args.port, open_browser=not args.no_browser)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
run()
|
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="fr">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>WebDisplay</title>
|
|
8
|
+
<style>
|
|
9
|
+
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap');
|
|
10
|
+
|
|
11
|
+
*,
|
|
12
|
+
*::before,
|
|
13
|
+
*::after {
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
margin: 0;
|
|
16
|
+
padding: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:root {
|
|
20
|
+
--bg: #0d0f11;
|
|
21
|
+
--surface: #141618;
|
|
22
|
+
--border: #232628;
|
|
23
|
+
--accent: #4af0a0;
|
|
24
|
+
--accent2: #1aff8c;
|
|
25
|
+
--dim: #3a4040;
|
|
26
|
+
--text: #c8d0cc;
|
|
27
|
+
--text-dim: #556060;
|
|
28
|
+
--mono: 'IBM Plex Mono', monospace;
|
|
29
|
+
--sans: 'IBM Plex Sans', sans-serif;
|
|
30
|
+
--radius: 6px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
html,
|
|
34
|
+
body {
|
|
35
|
+
height: 100%;
|
|
36
|
+
background: var(--bg);
|
|
37
|
+
color: var(--text);
|
|
38
|
+
font-family: var(--sans);
|
|
39
|
+
font-size: 14px;
|
|
40
|
+
line-height: 1.5;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* ── Layout ─────────────────────────────────────── */
|
|
44
|
+
body {
|
|
45
|
+
display: grid;
|
|
46
|
+
grid-template-rows: 48px 1fr;
|
|
47
|
+
grid-template-columns: 260px 1fr;
|
|
48
|
+
height: 100vh;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* ── Top bar ─────────────────────────────────────── */
|
|
53
|
+
header {
|
|
54
|
+
grid-column: 1 / -1;
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
gap: 16px;
|
|
58
|
+
padding: 0 20px;
|
|
59
|
+
border-bottom: 1px solid var(--border);
|
|
60
|
+
background: var(--surface);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.logo {
|
|
64
|
+
font-family: var(--mono);
|
|
65
|
+
font-size: 13px;
|
|
66
|
+
color: var(--accent);
|
|
67
|
+
letter-spacing: .04em;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.logo span {
|
|
71
|
+
color: var(--text-dim);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#status-dot {
|
|
75
|
+
width: 8px;
|
|
76
|
+
height: 8px;
|
|
77
|
+
border-radius: 50%;
|
|
78
|
+
background: var(--dim);
|
|
79
|
+
transition: background .3s;
|
|
80
|
+
flex-shrink: 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#status-dot.connected {
|
|
84
|
+
background: var(--accent);
|
|
85
|
+
box-shadow: 0 0 6px var(--accent);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#status-dot.reconnecting {
|
|
89
|
+
background: #f0a04a;
|
|
90
|
+
box-shadow: 0 0 6px #f0a04a;
|
|
91
|
+
animation: blink .8s ease-in-out infinite;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#status-dot.error {
|
|
95
|
+
background: #f04a4a;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@keyframes blink {
|
|
99
|
+
|
|
100
|
+
0%,
|
|
101
|
+
100% {
|
|
102
|
+
opacity: 1
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
50% {
|
|
106
|
+
opacity: .3
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#status-text {
|
|
111
|
+
font-family: var(--mono);
|
|
112
|
+
font-size: 11px;
|
|
113
|
+
color: var(--text-dim);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.spacer {
|
|
117
|
+
flex: 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#counter {
|
|
121
|
+
font-family: var(--mono);
|
|
122
|
+
font-size: 11px;
|
|
123
|
+
color: var(--text-dim);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#ws-url-input {
|
|
127
|
+
font-family: var(--mono);
|
|
128
|
+
font-size: 11px;
|
|
129
|
+
background: var(--bg);
|
|
130
|
+
border: 1px solid var(--border);
|
|
131
|
+
border-radius: var(--radius);
|
|
132
|
+
color: var(--text);
|
|
133
|
+
padding: 4px 10px;
|
|
134
|
+
width: 220px;
|
|
135
|
+
outline: none;
|
|
136
|
+
transition: border-color .2s;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#ws-url-input:focus {
|
|
140
|
+
border-color: var(--accent);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
button {
|
|
144
|
+
font-family: var(--mono);
|
|
145
|
+
font-size: 11px;
|
|
146
|
+
background: none;
|
|
147
|
+
border: 1px solid var(--dim);
|
|
148
|
+
border-radius: var(--radius);
|
|
149
|
+
color: var(--text-dim);
|
|
150
|
+
padding: 4px 12px;
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
transition: border-color .2s, color .2s;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
button:hover {
|
|
156
|
+
border-color: var(--accent);
|
|
157
|
+
color: var(--accent);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* ── Sidebar ─────────────────────────────────────── */
|
|
161
|
+
aside {
|
|
162
|
+
background: var(--surface);
|
|
163
|
+
border-right: 1px solid var(--border);
|
|
164
|
+
overflow-y: auto;
|
|
165
|
+
padding: 12px 8px;
|
|
166
|
+
display: flex;
|
|
167
|
+
flex-direction: column;
|
|
168
|
+
gap: 4px;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
aside h2 {
|
|
172
|
+
font-family: var(--mono);
|
|
173
|
+
font-size: 10px;
|
|
174
|
+
text-transform: uppercase;
|
|
175
|
+
letter-spacing: .1em;
|
|
176
|
+
color: var(--text-dim);
|
|
177
|
+
padding: 4px 8px 8px;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.thumb-item {
|
|
181
|
+
border-radius: var(--radius);
|
|
182
|
+
border: 1px solid transparent;
|
|
183
|
+
overflow: hidden;
|
|
184
|
+
cursor: pointer;
|
|
185
|
+
transition: border-color .15s, opacity .15s;
|
|
186
|
+
flex-shrink: 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.thumb-item:hover {
|
|
190
|
+
border-color: var(--dim);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.thumb-item.active {
|
|
194
|
+
border-color: var(--accent);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.thumb-item img {
|
|
198
|
+
width: 100%;
|
|
199
|
+
display: block;
|
|
200
|
+
border-radius: 4px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.thumb-meta {
|
|
204
|
+
padding: 4px 8px 6px;
|
|
205
|
+
font-family: var(--mono);
|
|
206
|
+
font-size: 10px;
|
|
207
|
+
color: var(--text-dim);
|
|
208
|
+
display: flex;
|
|
209
|
+
justify-content: space-between;
|
|
210
|
+
align-items: center;
|
|
211
|
+
gap: 4px;
|
|
212
|
+
overflow: hidden;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.thumb-title {
|
|
216
|
+
overflow: hidden;
|
|
217
|
+
text-overflow: ellipsis;
|
|
218
|
+
white-space: nowrap;
|
|
219
|
+
flex: 1;
|
|
220
|
+
color: var(--text);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* ── Main viewer ─────────────────────────────────── */
|
|
224
|
+
main {
|
|
225
|
+
overflow: hidden;
|
|
226
|
+
display: grid;
|
|
227
|
+
grid-template-rows: 1fr 36px;
|
|
228
|
+
background: var(--bg);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#viewer {
|
|
232
|
+
display: flex;
|
|
233
|
+
align-items: center;
|
|
234
|
+
justify-content: center;
|
|
235
|
+
overflow: hidden;
|
|
236
|
+
padding: 24px;
|
|
237
|
+
position: relative;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#viewer img {
|
|
241
|
+
max-width: 100%;
|
|
242
|
+
max-height: 100%;
|
|
243
|
+
object-fit: contain;
|
|
244
|
+
border-radius: 4px;
|
|
245
|
+
display: none;
|
|
246
|
+
transition: opacity .25s;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#viewer img.visible {
|
|
250
|
+
display: block;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
#empty-state {
|
|
254
|
+
display: flex;
|
|
255
|
+
flex-direction: column;
|
|
256
|
+
align-items: center;
|
|
257
|
+
gap: 12px;
|
|
258
|
+
color: var(--text-dim);
|
|
259
|
+
font-family: var(--mono);
|
|
260
|
+
font-size: 12px;
|
|
261
|
+
text-align: center;
|
|
262
|
+
line-height: 2;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
#empty-state .big {
|
|
266
|
+
font-size: 32px;
|
|
267
|
+
letter-spacing: .05em;
|
|
268
|
+
color: var(--dim);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* flash on new image */
|
|
272
|
+
@keyframes flash {
|
|
273
|
+
0% {
|
|
274
|
+
opacity: .7
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
100% {
|
|
278
|
+
opacity: 1
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.flash {
|
|
283
|
+
animation: flash .3s ease-out;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* ── Status bar ──────────────────────────────────── */
|
|
287
|
+
footer {
|
|
288
|
+
border-top: 1px solid var(--border);
|
|
289
|
+
display: flex;
|
|
290
|
+
align-items: center;
|
|
291
|
+
padding: 0 16px;
|
|
292
|
+
gap: 20px;
|
|
293
|
+
font-family: var(--mono);
|
|
294
|
+
font-size: 10px;
|
|
295
|
+
color: var(--text-dim);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
#img-info {
|
|
299
|
+
flex: 1;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
#img-time {}
|
|
303
|
+
|
|
304
|
+
/* ── Scrollbar ───────────────────────────────────── */
|
|
305
|
+
aside::-webkit-scrollbar {
|
|
306
|
+
width: 4px;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
aside::-webkit-scrollbar-track {
|
|
310
|
+
background: transparent;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
aside::-webkit-scrollbar-thumb {
|
|
314
|
+
background: var(--dim);
|
|
315
|
+
border-radius: 2px;
|
|
316
|
+
}
|
|
317
|
+
</style>
|
|
318
|
+
</head>
|
|
319
|
+
|
|
320
|
+
<body>
|
|
321
|
+
|
|
322
|
+
<header>
|
|
323
|
+
<div class="logo">web<span>/</span>display</div>
|
|
324
|
+
<div id="status-dot"></div>
|
|
325
|
+
<div id="status-text">déconnecté</div>
|
|
326
|
+
<div class="spacer"></div>
|
|
327
|
+
<div id="counter">0 image(s)</div>
|
|
328
|
+
<input id="ws-url-input" type="text" value="ws://localhost:8765/view" spellcheck="false">
|
|
329
|
+
<button id="connect-btn" onclick="toggleConnection()">Connecter</button>
|
|
330
|
+
<button id="clear-btn" onclick="clearHistory()">Effacer</button>
|
|
331
|
+
</header>
|
|
332
|
+
|
|
333
|
+
<aside>
|
|
334
|
+
<h2>Historique</h2>
|
|
335
|
+
<div id="thumb-list"></div>
|
|
336
|
+
</aside>
|
|
337
|
+
|
|
338
|
+
<main>
|
|
339
|
+
<div id="viewer">
|
|
340
|
+
<div id="empty-state">
|
|
341
|
+
<div class="big">⬡</div>
|
|
342
|
+
<div>En attente d'images…</div>
|
|
343
|
+
<div>Connectez-vous au relay, puis lancez<br>votre script Python.</div>
|
|
344
|
+
</div>
|
|
345
|
+
<img id="main-img" alt="image reçue">
|
|
346
|
+
</div>
|
|
347
|
+
<footer>
|
|
348
|
+
<span id="img-info">—</span>
|
|
349
|
+
<span id="img-time">—</span>
|
|
350
|
+
</footer>
|
|
351
|
+
</main>
|
|
352
|
+
|
|
353
|
+
<script>
|
|
354
|
+
let ws = null;
|
|
355
|
+
let images = []; // {title, data, time, size}
|
|
356
|
+
let current = -1;
|
|
357
|
+
|
|
358
|
+
// ── WebSocket ──────────────────────────────────────────────────────────────
|
|
359
|
+
|
|
360
|
+
function toggleConnection() {
|
|
361
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
362
|
+
ws.close();
|
|
363
|
+
} else {
|
|
364
|
+
connect();
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function connect() {
|
|
369
|
+
const url = document.getElementById('ws-url-input').value.trim();
|
|
370
|
+
setStatus('reconnecting', 'connexion…');
|
|
371
|
+
document.getElementById('connect-btn').textContent = 'Annuler';
|
|
372
|
+
|
|
373
|
+
try {
|
|
374
|
+
ws = new WebSocket(url);
|
|
375
|
+
} catch (e) {
|
|
376
|
+
setStatus('error', 'URL invalide');
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
ws.addEventListener('open', () => {
|
|
381
|
+
setStatus('connected', 'connecté · ' + url.replace('ws://', ''));
|
|
382
|
+
document.getElementById('connect-btn').textContent = 'Déconnecter';
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
ws.addEventListener('message', onMessage);
|
|
386
|
+
|
|
387
|
+
ws.addEventListener('close', () => {
|
|
388
|
+
setStatus('', 'déconnecté');
|
|
389
|
+
document.getElementById('connect-btn').textContent = 'Connecter';
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
ws.addEventListener('error', () => {
|
|
393
|
+
setStatus('error', 'erreur de connexion');
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function setStatus(cls, text) {
|
|
398
|
+
const dot = document.getElementById('status-dot');
|
|
399
|
+
const txt = document.getElementById('status-text');
|
|
400
|
+
dot.className = cls;
|
|
401
|
+
txt.textContent = text;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// ── Messages ───────────────────────────────────────────────────────────────
|
|
405
|
+
|
|
406
|
+
function onMessage(event) {
|
|
407
|
+
let payload;
|
|
408
|
+
try { payload = JSON.parse(event.data); } catch (e) { return; }
|
|
409
|
+
|
|
410
|
+
const { title = '', data } = payload;
|
|
411
|
+
if (!data) return;
|
|
412
|
+
|
|
413
|
+
const entry = {
|
|
414
|
+
title: title || ('image-' + (images.length + 1)),
|
|
415
|
+
data,
|
|
416
|
+
time: new Date().toLocaleTimeString('fr-FR'),
|
|
417
|
+
// taille approximative en ko
|
|
418
|
+
size: Math.round(data.length * 0.75 / 1024) + ' ko'
|
|
419
|
+
};
|
|
420
|
+
images.push(entry);
|
|
421
|
+
|
|
422
|
+
addThumb(entry, images.length - 1);
|
|
423
|
+
showImage(images.length - 1);
|
|
424
|
+
document.getElementById('counter').textContent = images.length + ' image(s)';
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// ── Thumbnails ─────────────────────────────────────────────────────────────
|
|
428
|
+
|
|
429
|
+
function addThumb(entry, idx) {
|
|
430
|
+
const list = document.getElementById('thumb-list');
|
|
431
|
+
|
|
432
|
+
const item = document.createElement('div');
|
|
433
|
+
item.className = 'thumb-item';
|
|
434
|
+
item.dataset.idx = idx;
|
|
435
|
+
item.onclick = () => showImage(idx);
|
|
436
|
+
|
|
437
|
+
const img = document.createElement('img');
|
|
438
|
+
img.src = 'data:image/png;base64,' + entry.data;
|
|
439
|
+
img.alt = entry.title;
|
|
440
|
+
|
|
441
|
+
const meta = document.createElement('div');
|
|
442
|
+
meta.className = 'thumb-meta';
|
|
443
|
+
meta.innerHTML = `
|
|
444
|
+
<span class="thumb-title">${escHtml(entry.title)}</span>
|
|
445
|
+
<span>${entry.time}</span>
|
|
446
|
+
`;
|
|
447
|
+
|
|
448
|
+
item.appendChild(img);
|
|
449
|
+
item.appendChild(meta);
|
|
450
|
+
list.appendChild(item);
|
|
451
|
+
item.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ── Viewer ──────────────────────────────────────────────────────────────────
|
|
455
|
+
|
|
456
|
+
function showImage(idx) {
|
|
457
|
+
if (idx < 0 || idx >= images.length) return;
|
|
458
|
+
current = idx;
|
|
459
|
+
|
|
460
|
+
const entry = images[idx];
|
|
461
|
+
const mainImg = document.getElementById('main-img');
|
|
462
|
+
const empty = document.getElementById('empty-state');
|
|
463
|
+
|
|
464
|
+
mainImg.src = 'data:image/png;base64,' + entry.data;
|
|
465
|
+
mainImg.classList.add('visible');
|
|
466
|
+
mainImg.classList.remove('flash');
|
|
467
|
+
void mainImg.offsetWidth; // reflow
|
|
468
|
+
mainImg.classList.add('flash');
|
|
469
|
+
empty.style.display = 'none';
|
|
470
|
+
|
|
471
|
+
document.getElementById('img-info').textContent =
|
|
472
|
+
`${entry.title} · ${entry.size}`;
|
|
473
|
+
document.getElementById('img-time').textContent = entry.time;
|
|
474
|
+
|
|
475
|
+
// Mise à jour de la sélection dans la sidebar
|
|
476
|
+
document.querySelectorAll('.thumb-item').forEach(el => {
|
|
477
|
+
el.classList.toggle('active', parseInt(el.dataset.idx) === idx);
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// ── Keyboard shortcuts ─────────────────────────────────────────────────────
|
|
482
|
+
|
|
483
|
+
document.addEventListener('keydown', e => {
|
|
484
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') showImage(current - 1);
|
|
485
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') showImage(current + 1);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
489
|
+
|
|
490
|
+
function escHtml(str) {
|
|
491
|
+
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// ── Clear history ──────────────────────────────────────────────────────────
|
|
495
|
+
|
|
496
|
+
function clearHistory() {
|
|
497
|
+
images = [];
|
|
498
|
+
current = -1;
|
|
499
|
+
document.getElementById('thumb-list').innerHTML = '';
|
|
500
|
+
document.getElementById('counter').textContent = '0 image(s)';
|
|
501
|
+
|
|
502
|
+
const mainImg = document.getElementById('main-img');
|
|
503
|
+
mainImg.src = '';
|
|
504
|
+
mainImg.classList.remove('visible');
|
|
505
|
+
document.getElementById('empty-state').style.display = '';
|
|
506
|
+
document.getElementById('img-info').textContent = '—';
|
|
507
|
+
document.getElementById('img-time').textContent = '—';
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Auto-connect au chargement
|
|
511
|
+
connect();
|
|
512
|
+
</script>
|
|
513
|
+
</body>
|
|
514
|
+
|
|
515
|
+
</html>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webdisplay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Un toolkit pour vite coder un modèle pytorch d'IA utilisant MLflow
|
|
5
|
+
Author-email: Jean-François Lecomte <zwergon@free.fr>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: websockets
|
|
11
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.rst
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/webdisplay/__init__.py
|
|
5
|
+
src/webdisplay/client.py
|
|
6
|
+
src/webdisplay/server.py
|
|
7
|
+
src/webdisplay.egg-info/PKG-INFO
|
|
8
|
+
src/webdisplay.egg-info/SOURCES.txt
|
|
9
|
+
src/webdisplay.egg-info/dependency_links.txt
|
|
10
|
+
src/webdisplay.egg-info/entry_points.txt
|
|
11
|
+
src/webdisplay.egg-info/requires.txt
|
|
12
|
+
src/webdisplay.egg-info/top_level.txt
|
|
13
|
+
src/webdisplay/static/index.html
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
websockets
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
webdisplay
|