Spaces:
Runtime error
Runtime error
Fix: Replace streaming with chained events to resolve ProtocolError
Browse files238 unmodified lines23924024124224324424524624724524624724824825024925025125218 unmodified lines27127227327527427527627741 unmodified lines31932032132332432532232332432532632732832933233333033133233333436 unmodified lines371372373376377378374375376377378379380381382383384385386387388389390391392393394395396397398381382399238 unmodified lines </div> """
def show_loader(): return LOADER_HTML
def run_benchmark(query): print(f"DEBUG: Starting benchmark for query: {query}") # 1. Yield Loader yield LOADER_HTML time.sleep(0.2) # Ensure loader renders before heavy processing try: # 2. Perform Search (Live) # Perform Search (Live) start_total = time.time() # Generate Embedding18 unmodified lines end_total = time.time() latency_ms = (end_total - start_total) * 1000 # 3. Construct Data Rows # Construct Data Rows # Live Row (MiniLM + LightGBM) # Mocking shards searched based on confidence for demo visual41 unmodified lines all_rows = [live_row] + ref_rows print("DEBUG: Yielding final HTML.") # 4. Yield Final HTML yield generate_table_html(all_rows) print("DEBUG: Returning final HTML.") return generate_table_html(all_rows)
except Exception as e: import traceback error_msg = traceback.format_exc() print(f"CRITICAL ERROR in run_benchmark: {error_msg}") # Yield Error HTML yield f""" # Return Error HTML return 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 Info gr.HTML(FOOTER_INFO_HTML)
# Interactions submit_btn.click(run_benchmark, inputs=[query_input], outputs=[results_area]) query_input.submit(run_benchmark, inputs=[query_input], outputs=[results_area]) # Interactions: Chained Events # 1. Show Loader immediately # 2. Run Benchmark and show results submit_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__": # Disable queue to prevent h11 LocalProtocolError on HF Spaces demo.launch() demo.queue().launch()app.py+33-16