File size: 1,673 Bytes
9129bee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

query = ExtractiveProposalQueries(es_host = Config.es_host, es_index = Config.proposals_index,
                                  es_user = Config.es_user, es_password = Config.es_password,
                                  reader_name_or_path = Config.reader_model_name_or_path,
                                  use_gpu = Config.use_gpu)


def update(query):
    return f"{query}", f"{query}", f"{query}", f"{query}"

def search(question):
  p1_result = query.search_by_query(query = question, retriever_top_k = 5, reader_top_k = 3, es_index = "petro")
  p2_result = query.search_by_query(query = question, retriever_top_k = 5, reader_top_k = 3, es_index = "rodolfo")

  return [p1_result[0].answer, 
          p1_result[0].context,
          p2_result[0].answer,
          p2_result[0].context]

demo = gr.Blocks()

with demo:
    gr.Markdown(
    """
    # Ask2Democracy
    Preguntale a los candidatos
    """)

    inp = gr.Textbox(placeholder="Haz tu pregunta aquΓ­")
    search_button = gr.Button("Buscar")
    with gr.Row():
      response = gr.Label(value="Petro")
      context = gr.Label(value="El viejo")
    with gr.Row():
      with gr.Column():      
#        resp_1 = gr.Markdown("<b>Respuesta</b>")
#        context_1 = gr.Markdown("<b>Contexto</b>")
        resp_1 = gr.Textbox(lines=1, label="respuesta")
        context_1 = gr.Textbox(lines=5, label="contexto")
      with gr.Column():      
        resp_2 = gr.Textbox(lines=1, label="respuesta")
        context_2 = gr.Textbox(lines=5, label="contexto")
    
      search_button.click(search, inputs = inp, outputs=[resp_1, context_1, resp_2, context_2])
demo.launch(debug = True)