Spaces:
Runtime error
Runtime error
Commit
·
393b8fc
1
Parent(s):
74ba34a
Fix ToC imports
Browse files- apps/article.py +1 -1
- apps/toc.py +0 -29
- apps/utils.py +28 -0
apps/article.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from apps.utils import read_markdown
|
| 3 |
from streamlit_tensorboard import st_tensorboard
|
| 4 |
-
from
|
| 5 |
def app(state):
|
| 6 |
toc = Toc()
|
| 7 |
st.title("Table of contents")
|
|
|
|
| 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):
|
| 6 |
toc = Toc()
|
| 7 |
st.title("Table of contents")
|
apps/toc.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
|
| 3 |
-
class Toc:
|
| 4 |
-
|
| 5 |
-
def __init__(self):
|
| 6 |
-
self._items = []
|
| 7 |
-
self._placeholder = None
|
| 8 |
-
|
| 9 |
-
def title(self, text):
|
| 10 |
-
self._markdown(text, "h1")
|
| 11 |
-
|
| 12 |
-
def header(self, text):
|
| 13 |
-
self._markdown(text, "h2", " " * 2)
|
| 14 |
-
|
| 15 |
-
def subheader(self, text):
|
| 16 |
-
self._markdown(text, "h3", " " * 4)
|
| 17 |
-
|
| 18 |
-
def placeholder(self, sidebar=False):
|
| 19 |
-
self._placeholder = st.sidebar.empty() if sidebar else st.empty()
|
| 20 |
-
|
| 21 |
-
def generate(self):
|
| 22 |
-
if self._placeholder:
|
| 23 |
-
self._placeholder.markdown("\n".join(self._items), unsafe_allow_html=True)
|
| 24 |
-
|
| 25 |
-
def _markdown(self, text, level, space=""):
|
| 26 |
-
key = "".join(filter(str.isalnum, text)).lower()
|
| 27 |
-
|
| 28 |
-
st.markdown(f"<{level} id='{key}'>{text}</{level}>", unsafe_allow_html=True)
|
| 29 |
-
self._items.append(f"{space}* <a href='#{key}'>{text}</a>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/utils.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
import plotly.express as px
|
| 5 |
import torch
|
| 6 |
from torchvision.io import read_image
|
|
@@ -8,6 +9,33 @@ from torchvision.transforms import CenterCrop, ConvertImageDtype, Normalize, Res
|
|
| 8 |
from torchvision.transforms.functional import InterpolationMode
|
| 9 |
from transformers import BertTokenizerFast
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
class Transform(torch.nn.Module):
|
| 13 |
def __init__(self, image_size):
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import numpy as np
|
| 4 |
+
import streamlit as st
|
| 5 |
import plotly.express as px
|
| 6 |
import torch
|
| 7 |
from torchvision.io import read_image
|
|
|
|
| 9 |
from torchvision.transforms.functional import InterpolationMode
|
| 10 |
from transformers import BertTokenizerFast
|
| 11 |
|
| 12 |
+
class Toc:
|
| 13 |
+
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self._items = []
|
| 16 |
+
self._placeholder = None
|
| 17 |
+
|
| 18 |
+
def title(self, text):
|
| 19 |
+
self._markdown(text, "h1")
|
| 20 |
+
|
| 21 |
+
def header(self, text):
|
| 22 |
+
self._markdown(text, "h2", " " * 2)
|
| 23 |
+
|
| 24 |
+
def subheader(self, text):
|
| 25 |
+
self._markdown(text, "h3", " " * 4)
|
| 26 |
+
|
| 27 |
+
def placeholder(self, sidebar=False):
|
| 28 |
+
self._placeholder = st.sidebar.empty() if sidebar else st.empty()
|
| 29 |
+
|
| 30 |
+
def generate(self):
|
| 31 |
+
if self._placeholder:
|
| 32 |
+
self._placeholder.markdown("\n".join(self._items), unsafe_allow_html=True)
|
| 33 |
+
|
| 34 |
+
def _markdown(self, text, level, space=""):
|
| 35 |
+
key = "".join(filter(str.isalnum, text)).lower()
|
| 36 |
+
|
| 37 |
+
st.markdown(f"<{level} id='{key}'>{text}</{level}>", unsafe_allow_html=True)
|
| 38 |
+
self._items.append(f"{space}* <a href='#{key}'>{text}</a>")
|
| 39 |
|
| 40 |
class Transform(torch.nn.Module):
|
| 41 |
def __init__(self, image_size):
|