styhero commited on
Commit
024c3d6
Β·
verified Β·
1 Parent(s): 79dff8e

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +49 -61
app.py CHANGED
@@ -386,9 +386,6 @@ st.markdown("""
386
  background:linear-gradient(90deg,#a78bfa,#e879f9);
387
  -webkit-background-clip:text;-webkit-text-fill-color:transparent;
388
  background-clip:text;line-height:1.2">Mobile Lookup</div>
389
- <div style="font-size:.72rem;color:rgba(180,180,220,.35);margin-top:3px;letter-spacing:.02em">
390
- DuckDB Β· HuggingFace Parquet
391
- </div>
392
  </div>
393
  </div>
394
  """, unsafe_allow_html=True)
@@ -405,71 +402,62 @@ if not submitted or not number.strip():
405
 
406
  target = number.strip()
407
 
408
- # ── Skeleton while loading ──────────────────────────────────────────────────────
409
-
410
- sk_placeholder = st.empty()
411
- sk_placeholder.markdown(SKELETONS_HTML, unsafe_allow_html=True)
412
-
413
- # ── Index lookup ────────────────────────────────────────────────────────────────
414
-
415
- t0 = time.perf_counter()
416
- idx_results = query_both_parallel(target)
417
- idx_ms = (time.perf_counter() - t0) * 1000
418
-
419
- m1_df, m1_ms = idx_results["mobile1"]
420
- m2_df, m2_ms = idx_results["mobile2"]
421
-
422
- if m1_df.empty and m2_df.empty:
423
- sk_placeholder.empty()
424
- st.markdown("""
425
- <div style="background:rgba(251,191,36,.08);border:1px solid rgba(251,191,36,.25);
426
- border-radius:10px;padding:12px 16px;color:#fbbf24;font-size:.9rem">
427
- No records found for <strong>{}</strong>
428
- </div>""".format(target), unsafe_allow_html=True)
429
- st.stop()
430
-
431
- # ── Row-group fetch ─────────────────────────────────────────────────────────────
432
-
433
- fetch_tasks = []
434
- for src_col, src_df in [("mobile1", m1_df), ("mobile2", m2_df)]:
435
- if src_df.empty:
436
- continue
437
- for _, rg in src_df[["filename","row_group_id","row_start","row_end"]].drop_duplicates().iterrows():
438
- fetch_tasks.append({
439
- "filename": str(rg["filename"]),
440
- "row_start": int(rg["row_start"]),
441
- "row_end": int(rg["row_end"]),
442
- "search_col": src_col,
443
- })
444
 
445
  all_dfs, errors = [], []
446
- with ThreadPoolExecutor(max_workers=min(8, len(fetch_tasks))) as ex:
447
- futures = {
448
- ex.submit(_fetch_one, t["filename"], t["row_start"], t["row_end"], t["search_col"], target): t
449
- for t in fetch_tasks
450
- }
451
- for f in as_completed(futures):
452
- try:
453
- df, _ = f.result()
454
- if not df.empty:
455
- all_dfs.append(df)
456
- except Exception as e:
457
- errors.append(str(e))
458
-
459
- fetch_ms = (time.perf_counter() - t0) * 1000
460
-
461
- # Clear skeleton
462
- sk_placeholder.empty()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
 
464
  for err in errors:
465
  st.error(err)
466
 
467
  if not all_dfs:
468
- st.markdown("""
469
- <div style="background:rgba(251,191,36,.08);border:1px solid rgba(251,191,36,.25);
470
- border-radius:10px;padding:12px 16px;color:#fbbf24;font-size:.9rem">
471
- No matching rows found in remote parquet.
472
- </div>""", unsafe_allow_html=True)
473
  st.stop()
474
 
475
  combined = pd.concat(all_dfs, ignore_index=True).drop_duplicates()
 
386
  background:linear-gradient(90deg,#a78bfa,#e879f9);
387
  -webkit-background-clip:text;-webkit-text-fill-color:transparent;
388
  background-clip:text;line-height:1.2">Mobile Lookup</div>
 
 
 
389
  </div>
390
  </div>
391
  """, unsafe_allow_html=True)
 
402
 
403
  target = number.strip()
404
 
405
+ # ── Search with progress ────────────────────────────────────────────────────────
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
 
407
  all_dfs, errors = [], []
408
+ t0 = time.perf_counter()
409
+
410
+ with st.status("Searching...", expanded=True) as status:
411
+
412
+ # Step 1 β€” index lookup
413
+ st.write("Querying mobile1 & mobile2 indexes in parallel...")
414
+ idx_results = query_both_parallel(target)
415
+ idx_ms = (time.perf_counter() - t0) * 1000
416
+ m1_df, m1_ms = idx_results["mobile1"]
417
+ m2_df, m2_ms = idx_results["mobile2"]
418
+ st.write(f"Index lookup done β€” {fmt_ms(idx_ms)}")
419
+
420
+ if m1_df.empty and m2_df.empty:
421
+ status.update(label="No records found", state="error", expanded=False)
422
+ st.warning(f"No records found for **{target}**")
423
+ st.stop()
424
+
425
+ # Step 2 β€” build fetch tasks
426
+ fetch_tasks = []
427
+ for src_col, src_df in [("mobile1", m1_df), ("mobile2", m2_df)]:
428
+ if src_df.empty:
429
+ continue
430
+ for _, rg in src_df[["filename","row_group_id","row_start","row_end"]].drop_duplicates().iterrows():
431
+ fetch_tasks.append({
432
+ "filename": str(rg["filename"]),
433
+ "row_start": int(rg["row_start"]),
434
+ "row_end": int(rg["row_end"]),
435
+ "search_col": src_col,
436
+ })
437
+
438
+ st.write(f"Fetching {len(fetch_tasks)} row group(s) from HuggingFace...")
439
+
440
+ with ThreadPoolExecutor(max_workers=min(8, len(fetch_tasks))) as ex:
441
+ futures = {
442
+ ex.submit(_fetch_one, t["filename"], t["row_start"], t["row_end"], t["search_col"], target): t
443
+ for t in fetch_tasks
444
+ }
445
+ for f in as_completed(futures):
446
+ try:
447
+ df, _ = f.result()
448
+ if not df.empty:
449
+ all_dfs.append(df)
450
+ except Exception as e:
451
+ errors.append(str(e))
452
+
453
+ fetch_ms = (time.perf_counter() - t0) * 1000
454
+ status.update(label=f"Done β€” {fmt_ms(fetch_ms)}", state="complete", expanded=False)
455
 
456
  for err in errors:
457
  st.error(err)
458
 
459
  if not all_dfs:
460
+ st.warning("No matching rows found in remote parquet.")
 
 
 
 
461
  st.stop()
462
 
463
  combined = pd.concat(all_dfs, ignore_index=True).drop_duplicates()