adithyajoseph commited on
Commit
e1777d4
Β·
verified Β·
1 Parent(s): 2840c62

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -41
app.py CHANGED
@@ -429,8 +429,8 @@ def ui_batch_scrape(states, cats, retries, force=False):
429
  """
430
  Runs Start Scraping -> auto Fix Missing Data -> auto push for each selected
431
  state in turn, so multiple states can be scraped unattended in one click.
432
- force=True skips the "already scraped" check (used after the user has
433
- explicitly confirmed a re-scrape for a single state).
434
  """
435
  from hf_store import check_state_scraped
436
 
@@ -506,11 +506,6 @@ def ui_batch_scrape(states, cats, retries, force=False):
506
  _batch_abort["flag"] = False
507
 
508
 
509
- def ui_main_scrape_forced(states, cats, retries):
510
- """Used after the user explicitly confirms re-scraping an already-scraped single state."""
511
- yield from ui_batch_scrape(states, cats, retries, force=True)
512
-
513
-
514
  # ── Dashboard helpers ─────────────────────────────────────────────────────────
515
  def _metric_card(label, value, color="#6366f1"):
516
  return f"""
@@ -955,11 +950,10 @@ with gr.Blocks(title="School Data Fetcher", css=css, theme=custom_theme) as app:
955
  scrape_btn = gr.Button("β–Ά Start Scraping", variant="primary", scale=3)
956
  stop_btn_placeholder = gr.HTML("", visible=False) # placeholder
957
 
958
- with gr.Column(visible=False) as confirm_col:
959
- gr.HTML("<div style='padding:15px; border-left:4px solid #f59e0b; background:#fffbeb; color:#92400e; border-radius:6px; margin: 10px 0;'><strong>⚠️ Warning:</strong> This state (and all selected categories) is already present in your dataset. Are you sure you want to scrape it again?</div>")
960
- with gr.Row():
961
- confirm_yes_btn = gr.Button("Yes, Scrape Again", variant="stop")
962
- confirm_no_btn = gr.Button("No, Cancel", variant="secondary")
963
 
964
  with gr.Row(visible=False) as stop_row:
965
  stop_btn = gr.Button("⏹ Stop", variant="stop", scale=1)
@@ -1005,18 +999,12 @@ with gr.Blocks(title="School Data Fetcher", css=css, theme=custom_theme) as app:
1005
  retry_row, stop_row,
1006
  ]
1007
 
1008
- def handle_scrape_click(states, categories):
1009
- from hf_store import check_state_scraped
1010
- states = states or []
1011
- if not states:
1012
- return gr.update(), gr.update(), False
1013
- if len(states) == 1 and check_state_scraped(states[0], categories):
1014
- return gr.update(visible=False), gr.update(visible=True), False
1015
- return gr.update(visible=False), gr.update(visible=False), True
1016
 
1017
- def ui_main_scrape_conditional(should_scrape, states, cats, retries):
1018
  if should_scrape:
1019
- yield from ui_batch_scrape(states, cats, retries, force=False)
1020
  else:
1021
  yield tuple(gr.update() for _ in range(10))
1022
 
@@ -1024,11 +1012,11 @@ with gr.Blocks(title="School Data Fetcher", css=css, theme=custom_theme) as app:
1024
 
1025
  scrape_btn.click(
1026
  fn=handle_scrape_click,
1027
- inputs=[state_dd, categories_cg],
1028
- outputs=[scrape_btn, confirm_col, should_scrape_state]
1029
  ).then(
1030
  fn=ui_main_scrape_conditional,
1031
- inputs=[should_scrape_state, state_dd, categories_cg, retries_slider],
1032
  outputs=batch_outputs
1033
  ).then(
1034
  fn=lambda should: gr.update(visible=True) if should else gr.update(),
@@ -1036,22 +1024,6 @@ with gr.Blocks(title="School Data Fetcher", css=css, theme=custom_theme) as app:
1036
  outputs=[scrape_btn]
1037
  )
1038
 
1039
- confirm_yes_btn.click(
1040
- fn=lambda: (gr.update(visible=False), gr.update(visible=False)),
1041
- outputs=[confirm_col, scrape_btn]
1042
- ).then(
1043
- fn=ui_main_scrape_forced,
1044
- inputs=[state_dd, categories_cg, retries_slider],
1045
- outputs=batch_outputs
1046
- ).then(
1047
- fn=lambda: gr.update(visible=True),
1048
- outputs=[scrape_btn]
1049
- )
1050
-
1051
- confirm_no_btn.click(
1052
- fn=lambda: (gr.update(visible=False), gr.update(visible=True)),
1053
- outputs=[confirm_col, scrape_btn]
1054
- )
1055
  retry_btn.click( fn=ui_retry, inputs=[state_dd, retries_slider], outputs=stream_outputs)
1056
  stop_btn.click( fn=ui_stop, inputs=[], outputs=[progress_html])
1057
 
 
429
  """
430
  Runs Start Scraping -> auto Fix Missing Data -> auto push for each selected
431
  state in turn, so multiple states can be scraped unattended in one click.
432
+ Any state already fully scraped for the selected categories is skipped
433
+ automatically (no confirmation prompt) unless force=True.
434
  """
435
  from hf_store import check_state_scraped
436
 
 
506
  _batch_abort["flag"] = False
507
 
508
 
 
 
 
 
 
509
  # ── Dashboard helpers ─────────────────────────────────────────────────────────
510
  def _metric_card(label, value, color="#6366f1"):
511
  return f"""
 
950
  scrape_btn = gr.Button("β–Ά Start Scraping", variant="primary", scale=3)
951
  stop_btn_placeholder = gr.HTML("", visible=False) # placeholder
952
 
953
+ force_rescrape_cb = gr.Checkbox(
954
+ label="Force re-scrape (overwrite states already fully scraped for these categories)",
955
+ value=False,
956
+ )
 
957
 
958
  with gr.Row(visible=False) as stop_row:
959
  stop_btn = gr.Button("⏹ Stop", variant="stop", scale=1)
 
999
  retry_row, stop_row,
1000
  ]
1001
 
1002
+ def handle_scrape_click(states):
1003
+ return (gr.update(visible=False), True) if states else (gr.update(), False)
 
 
 
 
 
 
1004
 
1005
+ def ui_main_scrape_conditional(should_scrape, states, cats, retries, force):
1006
  if should_scrape:
1007
+ yield from ui_batch_scrape(states, cats, retries, force=force)
1008
  else:
1009
  yield tuple(gr.update() for _ in range(10))
1010
 
 
1012
 
1013
  scrape_btn.click(
1014
  fn=handle_scrape_click,
1015
+ inputs=[state_dd],
1016
+ outputs=[scrape_btn, should_scrape_state]
1017
  ).then(
1018
  fn=ui_main_scrape_conditional,
1019
+ inputs=[should_scrape_state, state_dd, categories_cg, retries_slider, force_rescrape_cb],
1020
  outputs=batch_outputs
1021
  ).then(
1022
  fn=lambda should: gr.update(visible=True) if should else gr.update(),
 
1024
  outputs=[scrape_btn]
1025
  )
1026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1027
  retry_btn.click( fn=ui_retry, inputs=[state_dd, retries_slider], outputs=stream_outputs)
1028
  stop_btn.click( fn=ui_stop, inputs=[], outputs=[progress_html])
1029