Spaces:
Runtime error
Runtime error
Commit
·
6259d16
1
Parent(s):
8e7fd4d
Add local copy of st tensorboard
Browse files- apps/article.py +1 -1
- apps/streamlit_tensorboard.py +77 -0
- requirements.txt +1 -2
apps/article.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from apps.utils import read_markdown
|
| 3 |
-
from streamlit_tensorboard import st_tensorboard
|
| 4 |
from .utils import Toc
|
| 5 |
def app(state=None):
|
| 6 |
toc = Toc()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from apps.utils import read_markdown
|
| 3 |
+
from .streamlit_tensorboard import st_tensorboard
|
| 4 |
from .utils import Toc
|
| 5 |
def app(state=None):
|
| 6 |
toc = Toc()
|
apps/streamlit_tensorboard.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# https://github.com/snehankekre/streamlit-tensorboard/blob/master/streamlit_tensorboard/__init__.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import streamlit.components.v1 as components
|
| 4 |
+
from tensorboard import manager
|
| 5 |
+
import shlex
|
| 6 |
+
import random
|
| 7 |
+
import html
|
| 8 |
+
import json
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def st_tensorboard(logdir="/logs/", port=6006, width=None, height=800, scrolling=True):
|
| 12 |
+
"""Embed Tensorboard within a Streamlit app
|
| 13 |
+
Parameters
|
| 14 |
+
----------
|
| 15 |
+
logdir: str
|
| 16 |
+
Directory where TensorBoard will look to find TensorFlow event files that it can display.
|
| 17 |
+
TensorBoard will recursively walk the directory structure rooted at logdir, looking for .*tfevents.* files.
|
| 18 |
+
Defaults to /logs/
|
| 19 |
+
port: int
|
| 20 |
+
Port to serve TensorBoard on. Defaults to 6006
|
| 21 |
+
width: int
|
| 22 |
+
The width of the frame in CSS pixels. Defaults to the report’s default element width.
|
| 23 |
+
height: int
|
| 24 |
+
The height of the frame in CSS pixels. Defaults to 800.
|
| 25 |
+
scrolling: bool
|
| 26 |
+
If True, show a scrollbar when the content is larger than the iframe.
|
| 27 |
+
Otherwise, do not show a scrollbar. Defaults to True.
|
| 28 |
+
Example
|
| 29 |
+
-------
|
| 30 |
+
>>> st_tensorboard(logdir="/logs/", port=6006, width=1080)
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
logdir = logdir
|
| 34 |
+
port = port
|
| 35 |
+
width = width
|
| 36 |
+
height = height
|
| 37 |
+
|
| 38 |
+
frame_id = "tensorboard-frame-{:08x}".format(random.getrandbits(64))
|
| 39 |
+
shell = """
|
| 40 |
+
<iframe id="%HTML_ID%" width="100%" height="%HEIGHT%" frameborder="0">
|
| 41 |
+
</iframe>
|
| 42 |
+
<script>
|
| 43 |
+
(function() {
|
| 44 |
+
const frame = document.getElementById(%JSON_ID%);
|
| 45 |
+
const url = new URL(%URL%, window.location);
|
| 46 |
+
const port = %PORT%;
|
| 47 |
+
if (port) {
|
| 48 |
+
url.port = port;
|
| 49 |
+
}
|
| 50 |
+
frame.src = url;
|
| 51 |
+
})();
|
| 52 |
+
</script>
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
args_string = f"--logdir {logdir} --port {port}"
|
| 56 |
+
parsed_args = shlex.split(args_string, comments=True, posix=True)
|
| 57 |
+
start_result = manager.start(parsed_args)
|
| 58 |
+
|
| 59 |
+
if isinstance(start_result, manager.StartReused):
|
| 60 |
+
port = start_result.info.port
|
| 61 |
+
print(f"Reusing TensorBoard on port {port}")
|
| 62 |
+
|
| 63 |
+
proxy_url = "http://localhost:%PORT%"
|
| 64 |
+
|
| 65 |
+
proxy_url = proxy_url.replace("%PORT%", "%d" % port)
|
| 66 |
+
replacements = [
|
| 67 |
+
("%HTML_ID%", html.escape(frame_id, quote=True)),
|
| 68 |
+
("%JSON_ID%", json.dumps(frame_id)),
|
| 69 |
+
("%HEIGHT%", "%d" % height),
|
| 70 |
+
("%PORT%", "0"),
|
| 71 |
+
("%URL%", json.dumps(proxy_url)),
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
for (k, v) in replacements:
|
| 75 |
+
shell = shell.replace(k, v)
|
| 76 |
+
|
| 77 |
+
return components.html(shell, width=width, height=height, scrolling=scrolling)
|
requirements.txt
CHANGED
|
@@ -5,5 +5,4 @@ torchvision==0.10.0
|
|
| 5 |
mtranslate==1.8
|
| 6 |
black==21.7b0
|
| 7 |
flax==0.3.4
|
| 8 |
-
torch==1.9.0
|
| 9 |
-
streamlit-tensorboard==0.0.2
|
|
|
|
| 5 |
mtranslate==1.8
|
| 6 |
black==21.7b0
|
| 7 |
flax==0.3.4
|
| 8 |
+
torch==1.9.0
|
|
|