SergeyO7 commited on
Commit
b09aabe
·
verified ·
1 Parent(s): 8dcafa5

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +20 -3
Gradio_UI.py CHANGED
@@ -27,12 +27,20 @@ from smolagents.utils import _is_package_available
27
 
28
 
29
  def get_timezone_from_request(request) -> str:
30
- """Extract timezone from browser headers"""
31
  if request and hasattr(request, 'headers'):
 
 
 
 
 
 
 
 
 
32
  timezone_str = request.headers.get("gradio-timezone", None)
33
  if timezone_str:
34
  try:
35
- # Validate it's a proper timezone
36
  pytz.timezone(timezone_str)
37
  return timezone_str
38
  except pytz.UnknownTimeZoneError:
@@ -290,7 +298,16 @@ class GradioUI:
290
  def launch(self, **kwargs):
291
  import gradio as gr
292
 
293
- with gr.Blocks(fill_height=True) as demo:
 
 
 
 
 
 
 
 
 
294
  stored_messages = gr.State([])
295
  file_uploads_log = gr.State([])
296
  chatbot = gr.Chatbot(
 
27
 
28
 
29
  def get_timezone_from_request(request) -> str:
30
+ """Extract timezone from browser headers or from custom javascript"""
31
  if request and hasattr(request, 'headers'):
32
+ # Check for custom timezone header set by JavaScript
33
+ timezone_str = request.headers.get("x-timezone", None)
34
+ if timezone_str:
35
+ try:
36
+ pytz.timezone(timezone_str)
37
+ return timezone_str
38
+ except pytz.UnknownTimeZoneError:
39
+ pass
40
+ # Fallback to gradio-timezone if present
41
  timezone_str = request.headers.get("gradio-timezone", None)
42
  if timezone_str:
43
  try:
 
44
  pytz.timezone(timezone_str)
45
  return timezone_str
46
  except pytz.UnknownTimeZoneError:
 
298
  def launch(self, **kwargs):
299
  import gradio as gr
300
 
301
+ # JavaScript to get browser timezone and set it in headers
302
+ js = """
303
+ function() {
304
+ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
305
+ document.gradio_timezone = timezone;
306
+ return timezone;
307
+ }
308
+ """
309
+
310
+ with gr.Blocks(fill_height=True, js=js) as demo:
311
  stored_messages = gr.State([])
312
  file_uploads_log = gr.State([])
313
  chatbot = gr.Chatbot(