VED-AGI-1 commited on
Commit
5e87cca
·
verified ·
1 Parent(s): b7a949a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # app.py
2
  import os
3
  import time
4
  import re
@@ -277,14 +276,14 @@ def check_connection(user_tz=None):
277
  # UI
278
  # -------------------
279
  with gr.Blocks(theme=gr.themes.Default()) as demo:
280
- # Hold browser timezone (e.g., "America/Toronto")
281
- user_tz_state = gr.State("")
282
 
283
- # On load, capture browser timezone via JS and store in user_tz_state
284
  demo.load(
285
  fn=lambda tz: tz, # echo the JS value
286
  inputs=None,
287
- outputs=[user_tz_state], # outputs must be a LIST
288
  js="() => Intl.DateTimeFormat().resolvedOptions().timeZone"
289
  )
290
 
@@ -303,20 +302,20 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
303
  chat = gr.ChatInterface(
304
  fn=chat_fn,
305
  type="messages",
306
- additional_inputs=[user_tz_state], # pass timezone into chat_fn (for future use)
307
  description="A medical decision support system that provides healthcare-related information and decision making support.",
 
308
  examples=[
309
  ["What are the symptoms of hypertension?", ""],
310
  ["What are common drug interactions with aspirin?", ""],
311
  ["What are the warning signs of diabetes?", ""],
312
  ],
313
- cache_examples=False,
 
314
  )
315
 
316
  # Wire timezone into the connection check as well
317
- btn.click(fn=check_connection, inputs=user_tz_state, outputs=status)
318
 
319
  if __name__ == "__main__":
320
  demo.launch()
321
-
322
-
 
 
1
  import os
2
  import time
3
  import re
 
276
  # UI
277
  # -------------------
278
  with gr.Blocks(theme=gr.themes.Default()) as demo:
279
+ # Hidden textbox to hold browser timezone (Gradio expects components, not State)
280
+ tz_box = gr.Textbox(visible=False)
281
 
282
+ # On load, capture browser timezone via JS and store in tz_box
283
  demo.load(
284
  fn=lambda tz: tz, # echo the JS value
285
  inputs=None,
286
+ outputs=[tz_box], # outputs must be a LIST of components
287
  js="() => Intl.DateTimeFormat().resolvedOptions().timeZone"
288
  )
289
 
 
302
  chat = gr.ChatInterface(
303
  fn=chat_fn,
304
  type="messages",
305
+ additional_inputs=[tz_box], # pass timezone into chat_fn
306
  description="A medical decision support system that provides healthcare-related information and decision making support.",
307
+ # Each example is [message, timezone]; second field is a dummy since tz comes from JS.
308
  examples=[
309
  ["What are the symptoms of hypertension?", ""],
310
  ["What are common drug interactions with aspirin?", ""],
311
  ["What are the warning signs of diabetes?", ""],
312
  ],
313
+ cache_examples=True, # <- show examples on load (no precomputed outputs needed)
314
+ examples_per_page=3,
315
  )
316
 
317
  # Wire timezone into the connection check as well
318
+ btn.click(fn=check_connection, inputs=tz_box, outputs=status)
319
 
320
  if __name__ == "__main__":
321
  demo.launch()