Spaces:
Running
Running
go
Browse files- app.py +39 -30
- layouts/app.grid.json +119 -0
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# /// script
|
2 |
-
# requires-python = "==3.
|
3 |
# dependencies = [
|
4 |
# "marimo",
|
5 |
# "polars==1.23.0",
|
@@ -16,7 +16,7 @@
|
|
16 |
import marimo
|
17 |
|
18 |
__generated_with = "0.11.9"
|
19 |
-
app = marimo.App(width="medium")
|
20 |
|
21 |
|
22 |
@app.cell
|
@@ -27,9 +27,7 @@ def _(mo):
|
|
27 |
|
28 |
@app.cell
|
29 |
def _(mo, use_default_switch):
|
30 |
-
mo.
|
31 |
-
|
32 |
-
uploaded_file = mo.ui.file(kind="area")
|
33 |
uploaded_file
|
34 |
return (uploaded_file,)
|
35 |
|
@@ -49,14 +47,20 @@ def _(mo):
|
|
49 |
|
50 |
|
51 |
@app.cell
|
52 |
-
def _(
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
if use_default_switch.value:
|
56 |
df = pl.read_csv("spam.csv")
|
57 |
else:
|
58 |
-
df = pl.read_csv(
|
59 |
-
|
60 |
texts = df["text"].to_list()
|
61 |
return df, texts
|
62 |
|
@@ -151,12 +155,6 @@ def _():
|
|
151 |
return (br,)
|
152 |
|
153 |
|
154 |
-
@app.cell
|
155 |
-
def _(get_label):
|
156 |
-
get_label()
|
157 |
-
return
|
158 |
-
|
159 |
-
|
160 |
@app.cell
|
161 |
def _(mo, neg_label, pos_label):
|
162 |
get_label, set_label = mo.state({pos_label.value: [], neg_label.value: []})
|
@@ -205,6 +203,7 @@ def _(df_emb, mo, scatter):
|
|
205 |
@app.cell
|
206 |
def _(mo):
|
207 |
switch = mo.ui.switch(False, label="Use search")
|
|
|
208 |
return (switch,)
|
209 |
|
210 |
|
@@ -268,24 +267,34 @@ def _(
|
|
268 |
return df_emb, ham, i, labels, query, similarity, spam
|
269 |
|
270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
@app.cell
|
272 |
def _():
|
273 |
import marimo as mo
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
return (
|
281 |
-
LogisticRegression,
|
282 |
-
SentenceTransformer,
|
283 |
-
alt,
|
284 |
-
cosine_similarity,
|
285 |
-
mo,
|
286 |
-
np,
|
287 |
-
pl,
|
288 |
-
)
|
289 |
|
290 |
|
291 |
if __name__ == "__main__":
|
|
|
1 |
# /// script
|
2 |
+
# requires-python = "==3.12"
|
3 |
# dependencies = [
|
4 |
# "marimo",
|
5 |
# "polars==1.23.0",
|
|
|
16 |
import marimo
|
17 |
|
18 |
__generated_with = "0.11.9"
|
19 |
+
app = marimo.App(width="medium", layout_file="layouts/app.grid.json")
|
20 |
|
21 |
|
22 |
@app.cell
|
|
|
27 |
|
28 |
@app.cell
|
29 |
def _(mo, use_default_switch):
|
30 |
+
uploaded_file = mo.ui.file(kind="area") if not use_default_switch.value else None
|
|
|
|
|
31 |
uploaded_file
|
32 |
return (uploaded_file,)
|
33 |
|
|
|
47 |
|
48 |
|
49 |
@app.cell
|
50 |
+
def _(uploaded_file, use_default_switch):
|
51 |
+
should_stop = not use_default_switch.value and len(uploaded_file.value) == 0
|
52 |
+
return (should_stop,)
|
53 |
+
|
54 |
+
|
55 |
+
@app.cell
|
56 |
+
def _(mo, pl, should_stop, uploaded_file, use_default_switch):
|
57 |
+
mo.stop(should_stop , mo.md("**Submit a dataset or use default one to continue.**"))
|
58 |
|
59 |
if use_default_switch.value:
|
60 |
df = pl.read_csv("spam.csv")
|
61 |
else:
|
62 |
+
df = pl.read_csv(uploaded_file.value[0].contents)
|
63 |
+
|
64 |
texts = df["text"].to_list()
|
65 |
return df, texts
|
66 |
|
|
|
155 |
return (br,)
|
156 |
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
@app.cell
|
159 |
def _(mo, neg_label, pos_label):
|
160 |
get_label, set_label = mo.state({pos_label.value: [], neg_label.value: []})
|
|
|
203 |
@app.cell
|
204 |
def _(mo):
|
205 |
switch = mo.ui.switch(False, label="Use search")
|
206 |
+
switch
|
207 |
return (switch,)
|
208 |
|
209 |
|
|
|
267 |
return df_emb, ham, i, labels, query, similarity, spam
|
268 |
|
269 |
|
270 |
+
@app.cell
|
271 |
+
def _(mo):
|
272 |
+
|
273 |
+
with mo.status.spinner(subtitle="Loading libraries ...") as _spinner:
|
274 |
+
import polars as pl
|
275 |
+
import altair as alt
|
276 |
+
import numpy as np
|
277 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
278 |
+
from sklearn.linear_model import LogisticRegression
|
279 |
+
return LogisticRegression, alt, cosine_similarity, np, pl
|
280 |
+
|
281 |
+
|
282 |
+
@app.cell
|
283 |
+
def _(mo):
|
284 |
+
with mo.status.spinner(subtitle="Loading SBERT ...") as _spinner:
|
285 |
+
from sentence_transformers import SentenceTransformer
|
286 |
+
return (SentenceTransformer,)
|
287 |
+
|
288 |
+
|
289 |
@app.cell
|
290 |
def _():
|
291 |
import marimo as mo
|
292 |
+
return (mo,)
|
293 |
+
|
294 |
+
|
295 |
+
@app.cell
|
296 |
+
def _():
|
297 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
|
300 |
if __name__ == "__main__":
|
layouts/app.grid.json
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type": "grid",
|
3 |
+
"data": {
|
4 |
+
"columns": 24,
|
5 |
+
"rowHeight": 20,
|
6 |
+
"maxWidth": 1400,
|
7 |
+
"bordered": true,
|
8 |
+
"cells": [
|
9 |
+
{
|
10 |
+
"position": [
|
11 |
+
0,
|
12 |
+
0,
|
13 |
+
6,
|
14 |
+
2
|
15 |
+
]
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"position": [
|
19 |
+
6,
|
20 |
+
0,
|
21 |
+
11,
|
22 |
+
8
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"position": [
|
27 |
+
0,
|
28 |
+
5,
|
29 |
+
6,
|
30 |
+
3
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"position": null
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"position": null
|
38 |
+
},
|
39 |
+
{
|
40 |
+
"position": null
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"position": null
|
44 |
+
},
|
45 |
+
{
|
46 |
+
"position": null
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"position": null
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"position": null
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"position": [
|
56 |
+
0,
|
57 |
+
8,
|
58 |
+
13,
|
59 |
+
37
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"position": [
|
64 |
+
13,
|
65 |
+
18,
|
66 |
+
11,
|
67 |
+
23
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"position": null
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"position": null
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"position": null
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"position": null
|
81 |
+
},
|
82 |
+
{
|
83 |
+
"position": [
|
84 |
+
13,
|
85 |
+
16,
|
86 |
+
11,
|
87 |
+
2
|
88 |
+
]
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"position": null
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"position": null
|
95 |
+
},
|
96 |
+
{
|
97 |
+
"position": null
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"position": null
|
101 |
+
},
|
102 |
+
{
|
103 |
+
"position": null
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"position": null
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"position": null
|
110 |
+
},
|
111 |
+
{
|
112 |
+
"position": null
|
113 |
+
},
|
114 |
+
{
|
115 |
+
"position": null
|
116 |
+
}
|
117 |
+
]
|
118 |
+
}
|
119 |
+
}
|