VectorV17 commited on
Commit
863e7de
·
verified ·
1 Parent(s): fe673ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -40,19 +40,34 @@ Travelers and event attendees are always looking for specific logistical details
40
  """
41
 
42
  def get_thematic_datetime():
43
- """Generates precise ordinal date strings matching the UI (e.g., '08th June 2026')"""
 
 
 
44
  now = datetime.now()
45
- day = now.strftime("%d")
46
- if day.endswith("1") and day != "11": suffix = "st"
47
- elif day.endswith("2") and day != "12": suffix = "nd"
48
- elif day.endswith("3") and day != "13": suffix = "rd"
49
- else: suffix = "th"
50
- return f"{day}{suffix} {now.strftime('%B %Y').lower()} | time: {now.strftime('%I:%M%p').lower()}"
 
 
 
 
51
 
52
  def extract_text(content):
53
  """Safely extracts plain string text from any Gradio message structure."""
54
  if isinstance(content, str):
55
  return content
 
 
 
 
 
 
 
 
56
  if isinstance(content, dict):
57
  if "text" in content: return content["text"]
58
  if "content" in content: return content["content"]
@@ -186,7 +201,8 @@ with gr.Blocks() as demo:
186
  """
187
  )
188
  with gr.Column(scale=1):
189
- gr.HTML(f"<div style='text-align: right; font-weight: 500; font-size: 14px;'>{get_thematic_datetime()}</div>")
 
190
  toggle_btn = gr.Button("☀️/🌙 ➔ Change Mode (Day / Night)", elem_id="toggle-mode-btn")
191
  toggle_btn.click(None, None, None, js="() => document.body.classList.toggle('dark')")
192
 
@@ -211,7 +227,6 @@ with gr.Blocks() as demo:
211
  suggest_btn2 = gr.Button("How do I unlock my completion certificate?")
212
 
213
  with gr.Column(scale=1):
214
- # FIXED: Changed gr.Card to gr.Group
215
  with gr.Group(elem_id="right-meta-card"):
216
  gr.HTML(
217
  """
@@ -265,5 +280,9 @@ with gr.Blocks() as demo:
265
  bot_side, inputs=[chatbot, system_msg, max_tokens, temperature, top_p], outputs=[chatbot]
266
  )
267
 
 
 
 
 
268
  if __name__ == "__main__":
269
  demo.launch(css=custom_css, theme=gr.themes.Default())
 
40
  """
41
 
42
  def get_thematic_datetime():
43
+ """
44
+ Generates precise, real-time updated date and running seconds strings.
45
+ Returns complete styled HTML snippet to replace the old static header content.
46
+ """
47
  now = datetime.now()
48
+ day_int = now.day
49
+
50
+ # Handle English ordinal suffixes smoothly
51
+ if 11 <= day_int <= 13:
52
+ suffix = "th"
53
+ else:
54
+ suffix = {1: "st", 2: "nd", 3: "rd"}.get(day_int % 10, "th")
55
+
56
+ formatted_date = f"{now.strftime('%d')}{suffix} {now.strftime('%B %Y')} | Time: {now.strftime('%I:%M:%S %p').lower()}"
57
+ return f"<div style='text-align: right; font-weight: 600; font-size: 14px; font-family: monospace; letter-spacing: 0.5px;'>{formatted_date}</div>"
58
 
59
  def extract_text(content):
60
  """Safely extracts plain string text from any Gradio message structure."""
61
  if isinstance(content, str):
62
  return content
63
+ if isinstance(content, list):
64
+ extracted_parts = []
65
+ for block in content:
66
+ if isinstance(block, dict) and "text" in block:
67
+ extracted_parts.append(block["text"])
68
+ elif isinstance(block, str):
69
+ extracted_parts.append(block)
70
+ return "".join(extracted_parts)
71
  if isinstance(content, dict):
72
  if "text" in content: return content["text"]
73
  if "content" in content: return content["content"]
 
201
  """
202
  )
203
  with gr.Column(scale=1):
204
+ # FIXED: Set up an HTML component wrapper container initialized with current time
205
+ time_display = gr.HTML(value=get_thematic_datetime())
206
  toggle_btn = gr.Button("☀️/🌙 ➔ Change Mode (Day / Night)", elem_id="toggle-mode-btn")
207
  toggle_btn.click(None, None, None, js="() => document.body.classList.toggle('dark')")
208
 
 
227
  suggest_btn2 = gr.Button("How do I unlock my completion certificate?")
228
 
229
  with gr.Column(scale=1):
 
230
  with gr.Group(elem_id="right-meta-card"):
231
  gr.HTML(
232
  """
 
280
  bot_side, inputs=[chatbot, system_msg, max_tokens, temperature, top_p], outputs=[chatbot]
281
  )
282
 
283
+ # FIXED: Added a 1-second continuous background Timer to refresh the clock container
284
+ clock_timer = gr.Timer(every=1.0)
285
+ clock_timer.tick(fn=get_thematic_datetime, outputs=time_display, queue=False)
286
+
287
  if __name__ == "__main__":
288
  demo.launch(css=custom_css, theme=gr.themes.Default())