Rajan Sharma commited on
Commit
209eb3a
·
verified ·
1 Parent(s): 490d4fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
  import re
3
- from datetime import datetime, timezone
4
  from functools import lru_cache
 
5
 
6
  import gradio as gr
7
  import torch
@@ -12,7 +12,7 @@ try:
12
  except Exception:
13
  ZoneInfo = None
14
 
15
- # Cohere SDK
16
  try:
17
  import cohere
18
  _HAS_COHERE = True
@@ -58,8 +58,8 @@ def is_identity_query(message, history):
58
  return True
59
  return False
60
 
61
- # Build a simple prompt string for the older/stable Cohere chat API.
62
  def _history_to_prompt(message, history):
 
63
  parts = []
64
  for u, a in (history or []):
65
  if u:
@@ -79,7 +79,6 @@ if USE_HOSTED_COHERE:
79
 
80
  def cohere_chat(message, history):
81
  try:
82
- # Use the stable chat() API to avoid SDK breaking changes.
83
  prompt = _history_to_prompt(message, history)
84
  resp = _co_client.chat(
85
  model="command-r7b-12-2024",
@@ -87,7 +86,6 @@ def cohere_chat(message, history):
87
  temperature=0.3,
88
  max_tokens=350,
89
  )
90
- # Newer SDKs provide .text; older ones may use .reply or generations
91
  if hasattr(resp, "text") and resp.text:
92
  return resp.text.strip()
93
  if hasattr(resp, "reply") and resp.reply:
@@ -169,7 +167,7 @@ def chat_fn(message, history, user_tz):
169
  return f"Error: {e}"
170
 
171
  # -------------------
172
- # Theme & CSS (both bot and user bubbles teal + white text)
173
  # -------------------
174
  theme = gr.themes.Soft(
175
  primary_hue="teal",
@@ -181,19 +179,31 @@ custom_css = """
181
  :root {
182
  --brand-bg: #e6f7f8; /* soft medical teal */
183
  --brand-accent: #0d9488; /* teal-600 */
 
184
  --brand-text-light: #ffffff;
185
  }
186
 
 
187
  .gradio-container {
188
  background: var(--brand-bg);
189
  }
190
 
 
191
  h1 {
192
- color: #0f172a;
193
  font-weight: 700;
194
  font-size: 28px !important;
195
  }
196
 
 
 
 
 
 
 
 
 
 
197
  /* Both bot and user bubbles teal with white text */
198
  .message.user, .message.bot {
199
  background: var(--brand-accent) !important;
@@ -210,11 +220,12 @@ textarea, input, .gr-input {
210
  # UI
211
  # -------------------
212
  with gr.Blocks(theme=theme, css=custom_css) as demo:
 
213
  tz_box = gr.Textbox(visible=False)
214
  demo.load(lambda tz: tz, inputs=[tz_box], outputs=[tz_box],
215
  js="() => Intl.DateTimeFormat().resolvedOptions().timeZone")
216
 
217
- gr.Markdown("# ClarityOps Augmented Decision AI")
218
 
219
  gr.ChatInterface(
220
  fn=chat_fn,
@@ -234,3 +245,4 @@ if __name__ == "__main__":
234
 
235
 
236
 
 
 
1
  import os
2
  import re
 
3
  from functools import lru_cache
4
+ from datetime import datetime, timezone
5
 
6
  import gradio as gr
7
  import torch
 
12
  except Exception:
13
  ZoneInfo = None
14
 
15
+ # Cohere SDK (hosted path)
16
  try:
17
  import cohere
18
  _HAS_COHERE = True
 
58
  return True
59
  return False
60
 
 
61
  def _history_to_prompt(message, history):
62
+ """Build a simple text prompt for the stable cohere.chat API."""
63
  parts = []
64
  for u, a in (history or []):
65
  if u:
 
79
 
80
  def cohere_chat(message, history):
81
  try:
 
82
  prompt = _history_to_prompt(message, history)
83
  resp = _co_client.chat(
84
  model="command-r7b-12-2024",
 
86
  temperature=0.3,
87
  max_tokens=350,
88
  )
 
89
  if hasattr(resp, "text") and resp.text:
90
  return resp.text.strip()
91
  if hasattr(resp, "reply") and resp.reply:
 
167
  return f"Error: {e}"
168
 
169
  # -------------------
170
+ # Theme & CSS
171
  # -------------------
172
  theme = gr.themes.Soft(
173
  primary_hue="teal",
 
179
  :root {
180
  --brand-bg: #e6f7f8; /* soft medical teal */
181
  --brand-accent: #0d9488; /* teal-600 */
182
+ --brand-text: #0f172a;
183
  --brand-text-light: #ffffff;
184
  }
185
 
186
+ /* Page background */
187
  .gradio-container {
188
  background: var(--brand-bg);
189
  }
190
 
191
+ /* Title */
192
  h1 {
193
+ color: var(--brand-text);
194
  font-weight: 700;
195
  font-size: 28px !important;
196
  }
197
 
198
+ /* Hide the default "Chatbot" label pill in the top-left of the chat */
199
+ .chatbot .label,
200
+ .chatbot .label-wrap,
201
+ .chatbot header,
202
+ .chatbot .top,
203
+ .chatbot .header {
204
+ display: none !important;
205
+ }
206
+
207
  /* Both bot and user bubbles teal with white text */
208
  .message.user, .message.bot {
209
  background: var(--brand-accent) !important;
 
220
  # UI
221
  # -------------------
222
  with gr.Blocks(theme=theme, css=custom_css) as demo:
223
+ # Capture browser timezone (stored but not yet used)
224
  tz_box = gr.Textbox(visible=False)
225
  demo.load(lambda tz: tz, inputs=[tz_box], outputs=[tz_box],
226
  js="() => Intl.DateTimeFormat().resolvedOptions().timeZone")
227
 
228
+ gr.Markdown("# Medical Decision Support AI")
229
 
230
  gr.ChatInterface(
231
  fn=chat_fn,
 
245
 
246
 
247
 
248
+