Michael Bernovskiy commited on
Commit
c582f6b
1 Parent(s): 488bee9

reranker button added

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -34,7 +34,7 @@ def add_text(history, text):
34
  return history, gr.Textbox(value="", interactive=False)
35
 
36
 
37
- def bot(history, api_kind):
38
  query = history[-1][0]
39
 
40
  if not query:
@@ -46,13 +46,14 @@ def bot(history, api_kind):
46
 
47
  documents = retrieve(query, 10)
48
 
49
- document_time = perf_counter() - document_start
50
- logger.info(f'Finished Retrieving documents in {round(document_time, 2)} seconds...')
 
51
 
52
- rerank_start = perf_counter()
53
- documents = rerank(query, documents, TOP_K)
54
- rerank_time = perf_counter() - rerank_start
55
- logger.info(f'Finished Reranking documents in {round(rerank_time, 2)} seconds...')
56
 
57
  # Create Prompt
58
  prompt = template.render(documents=documents, query=query)
@@ -92,6 +93,7 @@ with gr.Blocks() as demo:
92
  txt_btn = gr.Button(value="Submit text", scale=1)
93
 
94
  api_kind = gr.Radio(choices=["HuggingFace", "OpenAI"], value="HuggingFace")
 
95
 
96
  prompt_html = gr.HTML()
97
  # Turn off interactivity while generating if you click
 
34
  return history, gr.Textbox(value="", interactive=False)
35
 
36
 
37
+ def bot(history, api_kind, use_reranker):
38
  query = history[-1][0]
39
 
40
  if not query:
 
46
 
47
  documents = retrieve(query, 10)
48
 
49
+ if use_reranker == "Yes":
50
+ document_time = perf_counter() - document_start
51
+ logger.info(f'Finished Retrieving documents in {round(document_time, 2)} seconds...')
52
 
53
+ rerank_start = perf_counter()
54
+ documents = rerank(query, documents, TOP_K)
55
+ rerank_time = perf_counter() - rerank_start
56
+ logger.info(f'Finished Reranking documents in {round(rerank_time, 2)} seconds...')
57
 
58
  # Create Prompt
59
  prompt = template.render(documents=documents, query=query)
 
93
  txt_btn = gr.Button(value="Submit text", scale=1)
94
 
95
  api_kind = gr.Radio(choices=["HuggingFace", "OpenAI"], value="HuggingFace")
96
+ use_reranker = gr.Radio(label="Use reranker?", choices=["Yes", "No"], value="Yes")
97
 
98
  prompt_html = gr.HTML()
99
  # Turn off interactivity while generating if you click