botsi commited on
Commit
31db25b
·
verified ·
1 Parent(s): 1fe71bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -17
app.py CHANGED
@@ -53,15 +53,6 @@ def fetch_personalized_data(session_index):
53
  print(f"Error: {err}")
54
  return None
55
 
56
- js = """
57
- function() {
58
- const params = new URLSearchParams(window.location.search);
59
- const url_params = Object.fromEntries(params);
60
- console.log("The console is working!);
61
- return url_params;
62
- }
63
- """
64
-
65
  def get_window_url_params():
66
  return """
67
  function() {
@@ -75,14 +66,8 @@ with gr.Blocks(js = js) as demo:
75
  gr.Markdown("""## Gradio send queryparam to chatbot
76
  type `hi`
77
  """)
78
- test = get_window_url_params()
79
- print("this is a test:" + test)
80
-
81
- session_index = 'eb3636167d3a63fbeee32934610e5b2f'
82
- personalized_data = fetch_personalized_data(session_index)
83
  url_params = gr.JSON({}, visible=False, label="URL Params")
84
- chatbot = gr.Chatbot()
85
- #chatbot = gr.Chatbot().style(height=500)
86
  msg = gr.Textbox()
87
  clear = gr.Button("Clear")
88
 
@@ -109,10 +94,17 @@ with gr.Blocks(js = js) as demo:
109
  time.sleep(1)
110
  return history
111
 
 
112
  msg.submit(user, inputs=[msg, url_params, chatbot], outputs=[msg, chatbot], queue=False).then(
113
  fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
114
  )
115
-
116
  clear.click(lambda: None, None, chatbot, queue=False)
 
 
 
 
 
 
 
117
 
118
  demo.launch()
 
53
  print(f"Error: {err}")
54
  return None
55
 
 
 
 
 
 
 
 
 
 
56
  def get_window_url_params():
57
  return """
58
  function() {
 
66
  gr.Markdown("""## Gradio send queryparam to chatbot
67
  type `hi`
68
  """)
 
 
 
 
 
69
  url_params = gr.JSON({}, visible=False, label="URL Params")
70
+ chatbot = gr.Chatbot().style(height=500)
 
71
  msg = gr.Textbox()
72
  clear = gr.Button("Clear")
73
 
 
94
  time.sleep(1)
95
  return history
96
 
97
+
98
  msg.submit(user, inputs=[msg, url_params, chatbot], outputs=[msg, chatbot], queue=False).then(
99
  fn=bot, inputs=[chatbot, url_params], outputs=[chatbot]
100
  )
 
101
  clear.click(lambda: None, None, chatbot, queue=False)
102
+ demo.load(
103
+ fn=lambda x: x,
104
+ inputs=[url_params],
105
+ outputs=[url_params],
106
+ _js=get_window_url_params,
107
+ queue=False
108
+ )
109
 
110
  demo.launch()