Spaces:
Sleeping
Sleeping
Add standalone search support
Browse files
app.py
CHANGED
@@ -329,9 +329,50 @@ def ChatFunc(message, history, LangMode, ChooseLang):
|
|
329 |
finally:
|
330 |
yield m.done()
|
331 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
|
334 |
resultTable = gr.Dataframe(datatype = ['html','number','number'], interactive = False, show_search = "search");
|
|
|
335 |
|
336 |
with gr.Blocks(fill_height=True) as demo:
|
337 |
|
@@ -367,8 +408,13 @@ with gr.Blocks(fill_height=True) as demo:
|
|
367 |
|
368 |
|
369 |
with gr.Tab("Rank"):
|
|
|
|
|
370 |
resultTable.render();
|
371 |
|
|
|
|
|
|
|
372 |
with gr.Tab("Help"):
|
373 |
gr.Markdown("""
|
374 |
Bem-vindo ao Space SQL Server Lib
|
@@ -405,6 +451,9 @@ with gr.Blocks(fill_height=True) as demo:
|
|
405 |
txtEmbed = gr.Text(label="Text to embed", visible=False)
|
406 |
btnEmbed = gr.Button("embed");
|
407 |
btnEmbed.click(embed, [txtEmbed], [txtEmbed])
|
|
|
|
|
|
|
408 |
|
409 |
|
410 |
|
|
|
329 |
finally:
|
330 |
yield m.done()
|
331 |
|
332 |
+
def SearchFiles(message, JsonOnly = False):
|
333 |
+
|
334 |
+
Question = message;
|
335 |
+
|
336 |
+
try:
|
337 |
+
FoundScripts = search(Question)
|
338 |
+
except:
|
339 |
+
return m("Houve alguma falha ao executar a consulta no banco. Tente novamente. Se persistir, veja orientações na aba Help!")
|
340 |
+
return;
|
341 |
+
|
342 |
+
doclist = [doc['ScriptContent'] for doc in FoundScripts]
|
343 |
|
344 |
+
# Faz o reranker!
|
345 |
+
|
346 |
+
|
347 |
+
|
348 |
+
ScriptTable = [];
|
349 |
+
for score in rerank(Question, doclist):
|
350 |
+
i = score['corpus_id'];
|
351 |
+
script = FoundScripts[i];
|
352 |
+
script['rank'] = str(score['score'])
|
353 |
+
link = "https://github.com/rrg92/sqlserver-lib/tree/main/" + script['RelPath']
|
354 |
+
script['link'] = link;
|
355 |
+
|
356 |
+
if not AsJson:
|
357 |
+
ScriptTable.append({
|
358 |
+
'Link': f'<a title="{link}" href="{link}" target="_blank">{script["RelPath"]}</a>'
|
359 |
+
,'Length': script['ContentLength']
|
360 |
+
,'Cosine Similarity': script['Similaridade']
|
361 |
+
,'Rank': script['rank']
|
362 |
+
})
|
363 |
+
|
364 |
+
RankedScripts = sorted(FoundScripts, key=lambda item: float(item['rank']), reverse=True)
|
365 |
+
|
366 |
+
result = pd.DataFrame(ScriptTable)
|
367 |
+
jsonresult = None;
|
368 |
+
if JsonOnly:
|
369 |
+
result = None;
|
370 |
+
jsonresult = json.dumps(RankedScripts)
|
371 |
+
|
372 |
+
return result,jsonresult;
|
373 |
|
374 |
resultTable = gr.Dataframe(datatype = ['html','number','number'], interactive = False, show_search = "search");
|
375 |
+
TextResults = gr.Textbox()
|
376 |
|
377 |
with gr.Blocks(fill_height=True) as demo:
|
378 |
|
|
|
408 |
|
409 |
|
410 |
with gr.Tab("Rank"):
|
411 |
+
txtSearchTable = gr.Textbox(label="Search script files",info="Description of what you want")
|
412 |
+
AsJson = gr.Checkbox(visible = False)
|
413 |
resultTable.render();
|
414 |
|
415 |
+
|
416 |
+
txtSearchTable.submit(SearchFiles, [txtSearchTable,AsJson],[resultTable,TextResults])
|
417 |
+
|
418 |
with gr.Tab("Help"):
|
419 |
gr.Markdown("""
|
420 |
Bem-vindo ao Space SQL Server Lib
|
|
|
451 |
txtEmbed = gr.Text(label="Text to embed", visible=False)
|
452 |
btnEmbed = gr.Button("embed");
|
453 |
btnEmbed.click(embed, [txtEmbed], [txtEmbed])
|
454 |
+
|
455 |
+
TextResults.render();
|
456 |
+
|
457 |
|
458 |
|
459 |
|