radames commited on
Commit
34eefa6
·
1 Parent(s): 1d56742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -12,7 +12,7 @@ get_window_url_params = """
12
  """
13
 
14
  with gr.Blocks() as demo:
15
- url_params = gr.JSON({}, visible=True, label="URL Params")
16
  chatbot = gr.Chatbot().style(height=500)
17
  msg = gr.Textbox()
18
  clear = gr.Button("Clear")
@@ -20,9 +20,12 @@ with gr.Blocks() as demo:
20
  def user(user_message, url_params, history):
21
  return "", history + [[user_message, None]]
22
 
23
- def bot(history):
24
  if "read query" in history[-1][0]:
25
- bot_message = f"```{json.dumps(url_params, indent=4)}```"
 
 
 
26
  else:
27
  bot_message = random.choice(["Yes", "No"])
28
  history[-1][1] = bot_message
@@ -30,15 +33,15 @@ with gr.Blocks() as demo:
30
  return history
31
 
32
  msg.submit(user, inputs=[msg, url_params, chatbot], outputs=[msg, chatbot], queue=False).then(
33
- bot, chatbot, chatbot
34
  )
35
  clear.click(lambda: None, None, chatbot, queue=False)
36
  demo.load(
37
- fn=lambda x:x,
38
  inputs=[url_params],
39
  outputs=[url_params],
40
  _js=get_window_url_params,
41
  queue=False
42
- )
43
 
44
- demo.launch()
 
12
  """
13
 
14
  with gr.Blocks() as demo:
15
+ url_params = gr.JSON({}, visible=False, label="URL Params")
16
  chatbot = gr.Chatbot().style(height=500)
17
  msg = gr.Textbox()
18
  clear = gr.Button("Clear")
 
20
  def user(user_message, url_params, history):
21
  return "", history + [[user_message, None]]
22
 
23
+ def bot(history, url_params):
24
  if "read query" in history[-1][0]:
25
+ bot_message = f"""
26
+ here your URL params:
27
+ {json.dumps(url_params, indent=4)}
28
+ """
29
  else:
30
  bot_message = random.choice(["Yes", "No"])
31
  history[-1][1] = bot_message
 
33
  return history
34
 
35
  msg.submit(user, inputs=[msg, url_params, chatbot], outputs=[msg, chatbot], queue=False).then(
36
+ fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
37
  )
38
  clear.click(lambda: None, None, chatbot, queue=False)
39
  demo.load(
40
+ fn=lambda x: x,
41
  inputs=[url_params],
42
  outputs=[url_params],
43
  _js=get_window_url_params,
44
  queue=False
45
+ )
46
 
47
+ demo.launch()