mpalinski commited on
Commit
baff125
·
verified ·
1 Parent(s): 21219fb

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -146,18 +146,19 @@ def _run_bur_embedding():
146
 
147
  st.info(f"Embedding {n:,} kompetencji (batch={BATCH_SIZE})…")
148
  embeddings_list = []
 
149
  pbar = st.progress(0.0, text=f"0 / {n:,} (0%)")
150
- batch_step = 50 # aktualizacja co 50 batchy – mniej overhead, stały postęp
151
  for i in range(0, n, BATCH_SIZE):
152
  batch = [(labels[j] or " ").strip() for j in range(i, min(i + BATCH_SIZE, n))]
153
  emb = encode_fn(batch, normalize_embeddings=True, batch_size=BATCH_SIZE, show_progress_bar=False)
154
  for k in range(len(batch)):
155
  embeddings_list.append(np.asarray(emb[k], dtype=np.float32))
156
  done = min(i + len(batch), n)
157
- if (i // BATCH_SIZE) % batch_step == 0 or done == n:
158
- pct = 100 * done / n
159
- pbar.progress(done / n, text=f"{done:,} / {n:,} ({pct:.1f}%)")
160
- time.sleep(0.05) # pozwala Streamlit wysłać aktualizację do frontendu
 
161
  pbar.progress(1.0, text=f"Gotowe: {n:,} (100%)")
162
 
163
  arr = np.stack(embeddings_list, axis=0)
@@ -211,8 +212,7 @@ def main():
211
  st.download_button("⬇️ bur_competencies_kalm_metadata.pkl", data=BUR_META.read_bytes(), file_name="bur_competencies_kalm_metadata.pkl", mime="application/octet-stream", key="bur_meta")
212
  else:
213
  if st.button("Uruchom embedding BUR", type="primary", key="bur_btn"):
214
- with st.spinner("Trwa embedding (~410k kompetencji, może 2–3 h)…"):
215
- _run_bur_embedding()
216
  st.rerun()
217
 
218
 
 
146
 
147
  st.info(f"Embedding {n:,} kompetencji (batch={BATCH_SIZE})…")
148
  embeddings_list = []
149
+ status_placeholder = st.empty()
150
  pbar = st.progress(0.0, text=f"0 / {n:,} (0%)")
 
151
  for i in range(0, n, BATCH_SIZE):
152
  batch = [(labels[j] or " ").strip() for j in range(i, min(i + BATCH_SIZE, n))]
153
  emb = encode_fn(batch, normalize_embeddings=True, batch_size=BATCH_SIZE, show_progress_bar=False)
154
  for k in range(len(batch)):
155
  embeddings_list.append(np.asarray(emb[k], dtype=np.float32))
156
  done = min(i + len(batch), n)
157
+ pct = 100 * done / n
158
+ status_placeholder.caption(f"📊 {done:,} / {n:,} ({pct:.1f}%)")
159
+ pbar.progress(done / n, text=f"{done:,} / {n:,} ({pct:.1f}%)")
160
+ time.sleep(0.08) # pozwala Streamlit wysłać aktualizację na HF (wolne WebSocket)
161
+ status_placeholder.empty()
162
  pbar.progress(1.0, text=f"Gotowe: {n:,} (100%)")
163
 
164
  arr = np.stack(embeddings_list, axis=0)
 
212
  st.download_button("⬇️ bur_competencies_kalm_metadata.pkl", data=BUR_META.read_bytes(), file_name="bur_competencies_kalm_metadata.pkl", mime="application/octet-stream", key="bur_meta")
213
  else:
214
  if st.button("Uruchom embedding BUR", type="primary", key="bur_btn"):
215
+ _run_bur_embedding()
 
216
  st.rerun()
217
 
218