Spaces:
Runtime error
Runtime error
Fix: Add try-except block to catch runtime errors and fix CSS
Browse files64 unmodified lines6566676869707172171 unmodified lines24424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832964 unmodified lines.search-row {display: flex !important;flex-direction: row !important;align-items: flex-start !important; /* Align top to handle potential textarea growth */gap: 1rem !important;}/* Loader Overlay */171 unmodified lines# 1. Yield Loaderyield LOADER_HTML# 2. Perform Search (Live)start_total = time.time()# Generate Embeddingtry:print("DEBUG: Generating embedding...")query_vec = get_embedding(query)print("DEBUG: Embedding generated.")except Exception as e:print(f"ERROR: Embedding failed: {e}")query_vec = [0.0] * VECTOR_SIZE # Dummy# Router Predictionif router:print("DEBUG: Predicting cluster...")target_cluster, confidence = router.predict(query_vec)print(f"DEBUG: Predicted cluster {target_cluster} with confidence {confidence}")else:print("DEBUG: No router loaded, using mock.")target_cluster, confidence = 0, 0.95 # Mock# Searchprint("DEBUG: Searching Qdrant...")results, mode = vector_db.search_hybrid(query_vec, target_cluster, confidence)print(f"DEBUG: Search complete. Found {len(results)} results.")end_total = time.time()latency_ms = (end_total - start_total) * 1000# 3. Construct Data Rows# Live Row (MiniLM + LightGBM)# Mocking shards searched based on confidence for demo visualshards_searched = 2 if confidence > 0.8 else 33total_shards = 33direct_time = latency_ms * (total_shards / shards_searched) * 1.2 # Estimate baselinelive_row = {"embedding": "MiniLM-L6-v2 (Active)","router": "LightGBM","optimizedTime": f"{latency_ms:.1f} ms","shardsSearched": f"{shards_searched} / {total_shards}","totalShards": total_shards,"accuracy": f"{confidence:.2f}","confDisplay": f"{confidence*100:.1f}%","directTime": f"{direct_time:.1f} ms","efficiency": f"+{((1 - latency_ms/direct_time)*100):.1f}%"}# Reference Rows (Static)ref_rows = [{"embedding": "Gemma 300M","router": "LightGBM","optimizedTime": "128 ms","shardsSearched": "9 / 16","totalShards": 16,"accuracy": "0.97","confDisplay": "97.1%","directTime": "220 ms","efficiency": "+41.8%"},{"embedding": "Qwen 600M","router": "XGBoost","optimizedTime": "109 ms","shardsSearched": "7 / 16","totalShards": 16,"accuracy": "0.90","confDisplay": "90.1%","directTime": "235 ms","efficiency": "+53.6%"}]all_rows = [live_row] + ref_rowsprint("DEBUG: Yielding final HTML.")# 4. Yield Final HTMLyield generate_table_html(all_rows)# --- Gradio App ---with gr.Blocks(theme=gr.themes.Base(), css=None, head=HEAD_HTML) as demo:64 unmodified lines656667686970717273171 unmodified lines24524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334464 unmodified lines.search-row {display: flex !important;flex-direction: row !important;align-items: flex-start !important;gap: 1rem !important;flex-wrap: nowrap !important; /* Prevent wrapping */}/* Loader Overlay */171 unmodified lines# 1. Yield Loaderyield LOADER_HTMLtry:# 2. Perform Search (Live)start_total = time.time()# Generate Embeddingprint("DEBUG: Generating embedding...")query_vec = get_embedding(query)print("DEBUG: Embedding generated.")# Router Predictionif router:print("DEBUG: Predicting cluster...")target_cluster, confidence = router.predict(query_vec)print(f"DEBUG: Predicted cluster {target_cluster} with confidence {confidence}")else:print("DEBUG: No router loaded, using mock.")target_cluster, confidence = 0, 0.95 # Mock# Searchprint("DEBUG: Searching Qdrant...")results, mode = vector_db.search_hybrid(query_vec, target_cluster, confidence)print(f"DEBUG: Search complete. Found {len(results)} results.")end_total = time.time()latency_ms = (end_total - start_total) * 1000# 3. Construct Data Rows# Live Row (MiniLM + LightGBM)# Mocking shards searched based on confidence for demo visualshards_searched = 2 if confidence > 0.8 else 33total_shards = 33direct_time = latency_ms * (total_shards / shards_searched) * 1.2 # Estimate baselinelive_row = {"embedding": "MiniLM-L6-v2 (Active)","router": "LightGBM","optimizedTime": f"{latency_ms:.1f} ms","shardsSearched": f"{shards_searched} / {total_shards}","totalShards": total_shards,"accuracy": f"{confidence:.2f}","confDisplay": f"{confidence*100:.1f}%","directTime": f"{direct_time:.1f} ms","efficiency": f"+{((1 - latency_ms/direct_time)*100):.1f}%"}# Reference Rows (Static)ref_rows = [{"embedding": "Gemma 300M","router": "LightGBM","optimizedTime": "128 ms","shardsSearched": "9 / 16","totalShards": 16,"accuracy": "0.97","confDisplay": "97.1%","directTime": "220 ms","efficiency": "+41.8%"},{"embedding": "Qwen 600M","router": "XGBoost","optimizedTime": "109 ms","shardsSearched": "7 / 16","totalShards": 16,"accuracy": "0.90","confDisplay": "90.1%","directTime": "235 ms","efficiency": "+53.6%"}]all_rows = [live_row] + ref_rowsprint("DEBUG: Yielding final HTML.")# 4. Yield Final HTMLyield generate_table_html(all_rows)except Exception as e:import tracebackerror_msg = traceback.format_exc()print(f"CRITICAL ERROR in run_benchmark: {error_msg}")# Yield Error HTMLyield f"""<div class="bg-red-50 border border-red-200 rounded-2xl p-6 text-red-800"><h3 class="font-bold text-lg mb-2 flex items-center gap-2"><span class="material-symbols-outlined">error</span>Runtime Error</h3><p class="mb-4">An error occurred while running the benchmark:</p><pre class="bg-red-100 p-4 rounded-lg text-xs font-mono overflow-x-auto">{error_msg}</pre></div>"""# --- Gradio App ---with gr.Blocks(theme=gr.themes.Base(), css=None, head=HEAD_HTML) as demo:
app.py+88-73