Karan Goel commited on
Commit
8634932
ยท
1 Parent(s): ccef048
Files changed (1) hide show
  1. tutorial-1.py +67 -0
tutorial-1.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import meerkat as mk
2
+
3
+
4
+ df = mk.get("imagenette", version="160px")
5
+ IMAGE_COL = "img"
6
+ LABEL_COL = "label"
7
+
8
+
9
+ @mk.reactive()
10
+ def random_images(df: mk.DataFrame):
11
+ images = df.sample(16)[IMAGE_COL]
12
+ formatter = images.formatters["base"]
13
+ return [formatter.encode(img) for img in images]
14
+
15
+ labels = list(df[LABEL_COL].unique())
16
+ class_selector = mk.gui.Select(
17
+ values=list(labels),
18
+ value=labels[0],
19
+ )
20
+
21
+ filtered_df = mk.reactive(lambda df, label: df[df[LABEL_COL] == label])(
22
+ df, class_selector.value
23
+ )
24
+
25
+ images = random_images(filtered_df)
26
+
27
+ grid = mk.gui.html.gridcols4(
28
+ [
29
+ mk.gui.html.div(mk.gui.Image(data=img), style="aspect-ratio: 1 / 1")
30
+ for img in images
31
+ ],
32
+ classes="gap-2",
33
+ )
34
+
35
+
36
+ layout = mk.gui.html.flexcol(
37
+ [
38
+ mk.gui.html.div(
39
+ [mk.gui.Caption("Choose a class:"), class_selector],
40
+ classes="flex justify-center items-center mb-2 gap-4",
41
+ ),
42
+ grid,
43
+ ]
44
+ )
45
+ page = mk.gui.Page(component=layout, id="tutorial-1")
46
+ import os
47
+ from fastapi.staticfiles import StaticFiles
48
+ # from meerkat.interactive.startup import file_find_replace
49
+ # print(os.getcwd())
50
+ # print(os.path.abspath("./meerkat/interactive/app/build/"))
51
+ # libpath = os.path.abspath("./meerkat/interactive/app/")
52
+ # api_url = "http://localhost:5000"
53
+ # file_find_replace(
54
+ # libpath + "build",
55
+ # r"(VITE_API_URL\|\|\".*?\")",
56
+ # f'VITE_API_URL||"{api_url}"',
57
+ # "*.js",
58
+ # )
59
+ # file_find_replace(
60
+ # libpath + ".svelte-kit/output/client/_app/",
61
+ # r"(VITE_API_URL\|\|\".*?\")",
62
+ # f'VITE_API_URL||"{api_url}"',
63
+ # "*.js",
64
+ # )
65
+ page().mount("/", StaticFiles(directory=os.path.abspath("./meerkat/interactive/app/build/"), html=True), "test")
66
+ # page().mount("/static", StaticFiles(directory=os.path.abspath("./temp/"),html = True), "test")
67
+ page.launch()