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