Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
UPDATE_SEARCH_RESULTS = f""" | |
function search(searchIn, maxResults = 3) {{ | |
if (searchIn.trim().length > 0) {{ | |
const results = []; | |
let titles = %s; | |
for (const title of titles) {{ // Assuming 'titles' is an array defined elsewhere | |
if (results.length > 10) {{ | |
break; | |
}} else {{ | |
if (title.toLowerCase().includes(searchIn.toLowerCase())) {{ // JavaScript's equivalent to Python's 'in' | |
results.push(title); | |
}} | |
}} | |
}} | |
// Handle UI elements (Explanation below) | |
const resultElements = [1,2,3,4,5,6,7,8,9,10].map(index => {{ | |
return results[index - 1] || ''; | |
}}); | |
if (resultElements[0] == '') {{ | |
document.getElementById('search_r1').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r1').style.display = 'block'; | |
}} | |
if (resultElements[1] == '') {{ | |
document.getElementById('search_r2').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r2').style.display = 'block'; | |
}} | |
if (resultElements[2] == '') {{ | |
document.getElementById('search_r3').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r3').style.display = 'block'; | |
}} | |
if (resultElements[3] == '') {{ | |
document.getElementById('search_r4').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r4').style.display = 'block'; | |
}} | |
if (resultElements[4] == '') {{ | |
document.getElementById('search_r5').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r5').style.display = 'block'; | |
}} | |
if (resultElements[5] == '') {{ | |
document.getElementById('search_r6').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r6').style.display = 'block'; | |
}} | |
if (resultElements[6] == '') {{ | |
document.getElementById('search_r7').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r7').style.display = 'block'; | |
}} | |
if (resultElements[7] == '') {{ | |
document.getElementById('search_r8').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r8').style.display = 'block'; | |
}} | |
if (resultElements[8] == '') {{ | |
document.getElementById('search_r9').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r9').style.display = 'block'; | |
}} | |
if (resultElements[9] == '') {{ | |
document.getElementById('search_r10').style.display = 'none'; | |
}} else {{ | |
document.getElementById('search_r10').style.display = 'block'; | |
}} | |
return resultElements; | |
}} else {{ | |
document.getElementById('search_r1').style.display = 'none'; | |
document.getElementById('search_r2').style.display = 'none'; | |
document.getElementById('search_r3').style.display = 'none'; | |
document.getElementById('search_r4').style.display = 'none'; | |
document.getElementById('search_r5').style.display = 'none'; | |
document.getElementById('search_r6').style.display = 'none'; | |
document.getElementById('search_r7').style.display = 'none'; | |
document.getElementById('search_r8').style.display = 'none'; | |
document.getElementById('search_r9').style.display = 'none'; | |
document.getElementById('search_r10').style.display = 'none'; | |
return ['', '', '', '', '', '', '', '', '', ''] | |
}} | |
}} | |
""" | |
UPDATE_IF_TYPE = f""" | |
function chage_if_type(if_type) {{ | |
if (if_type == 'Q&As') {{ | |
document.getElementById('chat_block').style.display = 'none'; | |
document.getElementById('qna_block').style.display = 'block'; | |
}} else {{ | |
document.getElementById('chat_block').style.display = 'block'; | |
document.getElementById('qna_block').style.display = 'none'; | |
}} | |
}} | |
""" |