CreatorPhan commited on
Commit
8469398
1 Parent(s): b66cd7a

Upload 4 files

Browse files
Files changed (2) hide show
  1. agent_t5.py +2 -2
  2. app.py +26 -11
agent_t5.py CHANGED
@@ -69,12 +69,12 @@ class Agent:
69
  sequence = self.tokenizer.decode(output, skip_special_tokens=True)
70
  answers.append(sequence)
71
 
72
- self.temp = contexts
73
  t_mess = "t_query: {:.2f}\t t_token: {:.2f}\t t_gen: {:.2f}\t t_decode: {:.2f}\t".format(
74
  s_token-s_query, s_gen-s_token, s_de-s_gen, time.time()-s_de
75
  )
76
  print(t_mess)
77
- return answers, contexts
78
 
79
 
80
 
 
69
  sequence = self.tokenizer.decode(output, skip_special_tokens=True)
70
  answers.append(sequence)
71
 
72
+ self.temp = [contexts, answers]
73
  t_mess = "t_query: {:.2f}\t t_token: {:.2f}\t t_gen: {:.2f}\t t_decode: {:.2f}\t".format(
74
  s_token-s_query, s_gen-s_token, s_de-s_gen, time.time()-s_de
75
  )
76
  print(t_mess)
77
+ return answers
78
 
79
 
80
 
app.py CHANGED
@@ -8,8 +8,7 @@ from retrieval.retrieval import BM25
8
 
9
  args = Config()
10
  chatbot = Agent(args)
11
- answer_areas = list(range(args.choices))
12
- context_areas = list(range(args.choices))
13
 
14
  with gr.Blocks() as demo:
15
  # gr.Markdown("Flip text or image files using this demo.")
@@ -19,10 +18,12 @@ with gr.Blocks() as demo:
19
  chatbot_area = gr.Chatbot().style(height=700)
20
  msg = gr.Textbox(label='Your prompt')
21
 
22
- with gr.Column(scale=0.15, min_width=300):
23
  for i in range(args.choices):
24
- with gr.Accordion(f"Answer: {i+1}", open=False) as answer_areas[i]:
25
- context_areas[i] = gr.Markdown(f"Context {i+1}")
 
 
26
  clear_chat = gr.Button("Clear history")
27
 
28
  with gr.Tab("Your context"):
@@ -45,11 +46,7 @@ with gr.Blocks() as demo:
45
  def bot(history):
46
  question = history[-1][0]
47
  print('User mess:', question)
48
- answers, contexts = chatbot.asking(question)
49
-
50
- for i in range(chatbot.choices):
51
- context_areas[i].value = contexts[i]['context']
52
- answer_areas[i].value = answers[i]
53
 
54
 
55
  print(answers)
@@ -58,14 +55,32 @@ with gr.Blocks() as demo:
58
  history[-1][1] += character
59
  time.sleep(0.01)
60
  yield history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  msg.submit(user, [msg, chatbot_area], [msg, chatbot_area], queue=False).then(
63
  bot, chatbot_area, chatbot_area
64
- )
65
 
66
  context_btt.click(chatbot.get_context, [context_box, ])
67
  upload_btt.upload(chatbot.load_context, [upload_btt, ], context_box)
68
  clear_context_btt.click(chatbot.clear_context, outputs=context_box)
 
69
 
70
  demo.queue()
71
  demo.launch()
 
8
 
9
  args = Config()
10
  chatbot = Agent(args)
11
+ RLHF = []
 
12
 
13
  with gr.Blocks() as demo:
14
  # gr.Markdown("Flip text or image files using this demo.")
 
18
  chatbot_area = gr.Chatbot().style(height=700)
19
  msg = gr.Textbox(label='Your prompt')
20
 
21
+ with gr.Column(scale=0.3, min_width=500):
22
  for i in range(args.choices):
23
+ with gr.Accordion(f"Answer {i+1}", open=False) as answer_area:
24
+ context_area = gr.Markdown(f"Context {i+1}")
25
+ RLHF.append(answer_area)
26
+ RLHF.append(context_area)
27
  clear_chat = gr.Button("Clear history")
28
 
29
  with gr.Tab("Your context"):
 
46
  def bot(history):
47
  question = history[-1][0]
48
  print('User mess:', question)
49
+ answers = chatbot.asking(question)
 
 
 
 
50
 
51
 
52
  print(answers)
 
55
  history[-1][1] += character
56
  time.sleep(0.01)
57
  yield history
58
+
59
+ def fill_feedback(prompt):
60
+ contexts, answers = chatbot.temp
61
+ outptus = []
62
+ for i in range(args.choices):
63
+ if i < chatbot.choices:
64
+ outptus.append(RLHF[2*i].update(label=answers[i], visible=True))
65
+ outptus.append(contexts[i]['context'])
66
+ else:
67
+ outptus.append(RLHF[2*i].update(visible=False))
68
+ outptus.append("No context")
69
+
70
+ return outptus
71
+
72
+ def clear_history(history):
73
+ history = []
74
+ return history
75
 
76
  msg.submit(user, [msg, chatbot_area], [msg, chatbot_area], queue=False).then(
77
  bot, chatbot_area, chatbot_area
78
+ ).then(fill_feedback, msg, RLHF)
79
 
80
  context_btt.click(chatbot.get_context, [context_box, ])
81
  upload_btt.upload(chatbot.load_context, [upload_btt, ], context_box)
82
  clear_context_btt.click(chatbot.clear_context, outputs=context_box)
83
+ clear_chat.click(clear_history, chatbot_area, chatbot_area)
84
 
85
  demo.queue()
86
  demo.launch()