Upload with huggingface_hub
Browse files- Dockerfile +34 -0
- tutorial-reactive-viewer.py +68 -0
Dockerfile
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
RUN chmod 777 /code
|
5 |
+
|
6 |
+
RUN useradd -m -u 1000 user
|
7 |
+
USER user
|
8 |
+
ENV HOME=/home/user \
|
9 |
+
PATH=/home/user/.local/bin:$PATH
|
10 |
+
WORKDIR $HOME
|
11 |
+
|
12 |
+
RUN git clone https://github.com/hazyresearch/meerkat.git
|
13 |
+
WORKDIR $HOME/meerkat/
|
14 |
+
RUN git checkout karan/deploy
|
15 |
+
RUN pip install --upgrade .
|
16 |
+
|
17 |
+
# PUT THIS BACK
|
18 |
+
# RUN pip install meerkat-ml
|
19 |
+
|
20 |
+
COPY --chown=user . $HOME/
|
21 |
+
|
22 |
+
# Set env variables
|
23 |
+
RUN mkdir $HOME/logs
|
24 |
+
RUN chmod 777 $HOME/logs
|
25 |
+
ENV MEERKAT_LOG_DIR=$HOME/logs
|
26 |
+
RUN chmod 777 $HOME/
|
27 |
+
ENV MEERKAT_CONFIG=$HOME/config.yaml
|
28 |
+
ENV SPACE_AUTHOR_NAME=krandiash
|
29 |
+
ENV SPACE_REPO_NAME=testing-3
|
30 |
+
|
31 |
+
COPY --chown=user ./.py $HOME/.py
|
32 |
+
|
33 |
+
WORKDIR $HOME
|
34 |
+
CMD ["mk", "run", "/home/user/.py", "--host", "0.0.0.0", "--api-port", "7860"]
|
tutorial-reactive-viewer.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""A reactive image viewer that allows you to select a class and see 16 random
|
2 |
+
images from that class.
|
3 |
+
|
4 |
+
This is a tutorial on how to use `reactive` functions in Meerkat, to
|
5 |
+
build complex reactive workflows.
|
6 |
+
"""
|
7 |
+
|
8 |
+
import meerkat as mk
|
9 |
+
|
10 |
+
df = mk.get("imagenette", version="160px")
|
11 |
+
IMAGE_COL = "img"
|
12 |
+
LABEL_COL = "label"
|
13 |
+
|
14 |
+
|
15 |
+
@mk.reactive()
|
16 |
+
def random_images(df: mk.DataFrame):
|
17 |
+
images = df.sample(16)[IMAGE_COL]
|
18 |
+
formatter = images.formatters["base"]
|
19 |
+
# formatter = images.formatters['tiny']
|
20 |
+
return [formatter.encode(img) for img in images]
|
21 |
+
|
22 |
+
|
23 |
+
labels = list(df[LABEL_COL].unique())
|
24 |
+
class_selector = mk.gui.Select(
|
25 |
+
values=list(labels),
|
26 |
+
value=labels[0],
|
27 |
+
)
|
28 |
+
|
29 |
+
# Note that neither of these will work:
|
30 |
+
# filtered_df = df[df[LABEL_COL] == class_selector.value]
|
31 |
+
# (doesn't react to changes in class_selector.value)
|
32 |
+
# filtered_df = mk.reactive(lambda df: df[df[LABEL_COL] == class_selector.value])(df)
|
33 |
+
# (doesn't react to changes in class_selector.value)
|
34 |
+
filtered_df = mk.reactive(lambda df, label: df[df[LABEL_COL] == label])(
|
35 |
+
df, class_selector.value
|
36 |
+
)
|
37 |
+
|
38 |
+
images = random_images(filtered_df)
|
39 |
+
|
40 |
+
# This won't work with a simple reactive fn like a random_images
|
41 |
+
# that only has df.sample
|
42 |
+
# as the encoding needs to be done in the reactive fn
|
43 |
+
# grid = mk.gui.html.gridcols2([
|
44 |
+
# mk.gui.Image(data=images.formatters["base"].encode(img)) for img in images
|
45 |
+
# ])
|
46 |
+
|
47 |
+
grid = mk.gui.html.div(
|
48 |
+
[
|
49 |
+
# Make the image square
|
50 |
+
mk.gui.html.div(mk.gui.Image(data=img))
|
51 |
+
for img in images
|
52 |
+
],
|
53 |
+
classes="h-fit grid grid-cols-4 gap-1",
|
54 |
+
)
|
55 |
+
|
56 |
+
layout = mk.gui.html.div(
|
57 |
+
[
|
58 |
+
mk.gui.html.div(
|
59 |
+
[mk.gui.Caption("Choose a class:"), class_selector],
|
60 |
+
classes="flex justify-center items-center mb-2 gap-2",
|
61 |
+
),
|
62 |
+
grid,
|
63 |
+
],
|
64 |
+
classes="h-full flex flex-col m-2",
|
65 |
+
)
|
66 |
+
|
67 |
+
page = mk.gui.Page(layout, id="reactive-viewer")
|
68 |
+
page.launch()
|