File size: 2,065 Bytes
e137e27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
from fasthtml.common import *
from fasthtml.components import *
import json
import string
import random
def gen_random_id() -> str:
return "".join(random.choices(string.ascii_lowercase, k=8))
def view_data(
before,
after,
doc_id,
data_source: str = None,
data_sources=None,
target: str = "colcontent",
):
if data_sources is not None:
drop_down = Select(
*[
Option(ds, value=ds, selected=(ds == data_source))
for ds in data_sources
],
name=f"data_source_{target}",
hx_get=f"/curated/{target}",
hx_target=f"#{target}",
hx_trigger="change",
hx_swap="innerHTML",
)
slider = Input(
type="range",
name=f"doc_id_{target}",
min="0",
max="9",
value=str(doc_id),
hx_get=f"/curated/{target}",
hx_target=f"#{target}",
hx_trigger="change",
hx_swap="innerHTML",
hx_include=f'[name="data_source_{target}"]',
)
form = Form(
Div(
Label("Data source: ", drop_down),
)
if (data_sources is not None)
else None,
Div(
Label("Data sample: ", slider, f"{doc_id}", cls="plotly_slider"),
),
cls="plotly_input_container",
)
col1 = Div(
H3("Raw format"),
Pre(
json.dumps(before, indent=4),
style="white-space: pre-wrap; word-break: break-all;",
),
style="width: 48%; float: left; overflow-x: auto;",
)
col2 = Div(
H3("Extracted format"),
Pre(
json.dumps(after, indent=4),
style="white-space: pre-wrap; word-break: break-all;",
),
style="width: 48%; float: right; overflow-x: auto;",
)
data_display = Div(
col1,
col2,
style="overflow: auto; clear: both; height: 600px; border: 1px solid #ccc; padding: 20px;",
)
return Div(form, data_display, style="margin-top: 10px;", id=target)
|