Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 4,111 Bytes
3993884 a7ff712 3993884 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
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';
}}
}}
""" |