Spaces:
Runtime error
Runtime error
Fix: Replace streaming with chained events to resolve ProtocolError
Browse files238 unmodified lines23924024124224324424524624724824925025125225318 unmodified lines27227327427527627727841 unmodified lines32032132232332432532632732832933033133233333433533636 unmodified lines373374375376377378379380381382238 unmodified lines</div>"""def run_benchmark(query):print(f"DEBUG: Starting benchmark for query: {query}")# 1. Yield Loaderyield LOADER_HTMLtime.sleep(0.2) # Ensure loader renders before heavy processingtry:# 2. Perform Search (Live)start_total = time.time()# Generate Embedding18 unmodified linesend_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 visual41 unmodified linesall_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>36 unmodified lines# Footer Infogr.HTML(FOOTER_INFO_HTML)# Interactionssubmit_btn.click(run_benchmark, inputs=[query_input], outputs=[results_area])query_input.submit(run_benchmark, inputs=[query_input], outputs=[results_area])if __name__ == "__main__":# Disable queue to prevent h11 LocalProtocolError on HF Spacesdemo.launch()238 unmodified lines23924024124224324424524624724824925025125218 unmodified lines27127227327427527627741 unmodified lines31932032132232332432532632732832933033133233333436 unmodified lines371372373374375376377378379380381382383384385386387388389390391392393394395396397398399238 unmodified lines</div>"""def show_loader():return LOADER_HTMLdef run_benchmark(query):print(f"DEBUG: Starting benchmark for query: {query}")try:# Perform Search (Live)start_total = time.time()# Generate Embedding18 unmodified linesend_total = time.time()latency_ms = (end_total - start_total) * 1000# Construct Data Rows# Live Row (MiniLM + LightGBM)# Mocking shards searched based on confidence for demo visual41 unmodified linesall_rows = [live_row] + ref_rowsprint("DEBUG: Returning final HTML.")return generate_table_html(all_rows)except Exception as e:import tracebackerror_msg = traceback.format_exc()print(f"CRITICAL ERROR in run_benchmark: {error_msg}")# Return Error HTMLreturn 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>36 unmodified lines# Footer Infogr.HTML(FOOTER_INFO_HTML)# Interactions: Chained Events# 1. Show Loader immediately# 2. Run Benchmark and show resultssubmit_btn.click(show_loader,inputs=None,outputs=[results_area]).then(run_benchmark,inputs=[query_input],outputs=[results_area])query_input.submit(show_loader,inputs=None,outputs=[results_area]).then(run_benchmark,inputs=[query_input],outputs=[results_area])if __name__ == "__main__":demo.queue().launch()
app.py+33-16