omkarenator commited on
Commit
7e8dbcd
·
1 Parent(s): b77de16

fix drop down

Browse files
Files changed (2) hide show
  1. curated.py +15 -11
  2. main.py +4 -7
curated.py CHANGED
@@ -20,8 +20,8 @@ data_sources = [
20
  ]
21
 
22
 
23
- def get_data(data_source: str = "Freelaw", data_ext_doc_id: int = 3, htmx=None):
24
- data_ext_doc_id = max(0, min(int(data_ext_doc_id), 9))
25
 
26
  if data_source == "Freelaw":
27
  raw_sample_doc = json.load(open("data/curated_samples/freelaw_raw.json"))
@@ -57,8 +57,8 @@ def get_data(data_source: str = "Freelaw", data_ext_doc_id: int = 3, htmx=None):
57
  else:
58
  raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]
59
 
60
- raw_json = raw_sample_doc[data_ext_doc_id]
61
- extracted_json = extracted_sample_doc[data_ext_doc_id]
62
 
63
  drop_down = Select(
64
  *[Option(ds, value=ds, selected=(ds == data_source)) for ds in data_sources],
@@ -71,24 +71,24 @@ def get_data(data_source: str = "Freelaw", data_ext_doc_id: int = 3, htmx=None):
71
 
72
  slider = Input(
73
  type="range",
74
- name="data_ext_doc_id",
75
  min="0",
76
  max="9",
77
- value=str(data_ext_doc_id),
78
  hx_get="/curated",
79
  hx_target="#colcontent",
80
  hx_trigger="change",
81
  hx_swap="innerHTML",
82
- oninput='document.getElementById("doc_id_value").innerText = "Selected document index: " + this.value',
83
  )
84
 
85
  form = Form(
86
  Div(
87
- Label("Data source:", drop_down),
88
  style="margin-bottom: 20px;",
89
  ),
90
  Div(
91
- Label("Data sample:", slider, f"{data_ext_doc_id}"),
92
  style="margin-bottom: 20px;",
93
  ),
94
  )
@@ -111,5 +111,9 @@ def get_data(data_source: str = "Freelaw", data_ext_doc_id: int = 3, htmx=None):
111
  style="width: 48%; float: right; overflow-x: auto;",
112
  )
113
 
114
- data_display = Div(col1, col2, style="overflow: auto; clear: both; height: 600px;")
115
- return (Div(form, data_display, style="margin-top: 10px;", id="colcontent"),)
 
 
 
 
 
20
  ]
21
 
22
 
23
+ def get_data(data_source: str = "Freelaw", doc_id: int = 3):
24
+ doc_id = max(0, min(int(doc_id), 9))
25
 
26
  if data_source == "Freelaw":
27
  raw_sample_doc = json.load(open("data/curated_samples/freelaw_raw.json"))
 
57
  else:
58
  raw_sample_doc = extracted_sample_doc = [{} for _ in range(10)]
59
 
60
+ raw_json = raw_sample_doc[doc_id]
61
+ extracted_json = extracted_sample_doc[doc_id]
62
 
63
  drop_down = Select(
64
  *[Option(ds, value=ds, selected=(ds == data_source)) for ds in data_sources],
 
71
 
72
  slider = Input(
73
  type="range",
74
+ name="doc_id",
75
  min="0",
76
  max="9",
77
+ value=str(doc_id),
78
  hx_get="/curated",
79
  hx_target="#colcontent",
80
  hx_trigger="change",
81
  hx_swap="innerHTML",
82
+ hx_include="[name='data_source']",
83
  )
84
 
85
  form = Form(
86
  Div(
87
+ Label("Data source: ", drop_down),
88
  style="margin-bottom: 20px;",
89
  ),
90
  Div(
91
+ Label("Data sample: ", slider, f"{doc_id}"),
92
  style="margin-bottom: 20px;",
93
  ),
94
  )
 
111
  style="width: 48%; float: right; overflow-x: auto;",
112
  )
113
 
114
+ data_display = Div(
115
+ col1,
116
+ col2,
117
+ style="overflow: auto; clear: both; height: 600px; border: 1px solid #ccc; padding: 20px;",
118
+ )
119
+ return Div(form, data_display, style="margin-top: 10px;", id="colcontent")
main.py CHANGED
@@ -311,12 +311,12 @@ def get_chart_28168342():
311
  def curated(request):
312
  from curated import get_data
313
 
314
- # Partial Update
315
  params = request.query_params
316
  if data_source := params.get("data_source"):
317
- return get_data(data_source=data_source)
318
- if doc_id := params.get("data_ext_doc_id"):
319
- return get_data(data_ext_doc_id=doc_id)
320
 
321
  hr = HR()
322
  data_preparation_steps = pd.DataFrame(
@@ -345,9 +345,6 @@ def curated(request):
345
  }
346
  )
347
 
348
- data_preparation_steps = data_preparation_steps.style.set_properties(
349
- **{"padding": "10px"}
350
- )
351
  table_html = data_preparation_steps.to_html(index=False, border=0)
352
  table_div = Div(NotStr(table_html), cls="l-body-outset")
353
 
 
311
  def curated(request):
312
  from curated import get_data
313
 
314
+ # Partial Updates
315
  params = request.query_params
316
  if data_source := params.get("data_source"):
317
+ return get_data(data_source, params.get("doc_id", 3))
318
+ if doc_id := params.get("doc_id"):
319
+ return get_data(params.get("data_source"), doc_id)
320
 
321
  hr = HR()
322
  data_preparation_steps = pd.DataFrame(
 
345
  }
346
  )
347
 
 
 
 
348
  table_html = data_preparation_steps.to_html(index=False, border=0)
349
  table_div = Div(NotStr(table_html), cls="l-body-outset")
350