Rajan Sharma commited on
Commit
6b58036
·
verified ·
1 Parent(s): 393880f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -46
app.py CHANGED
@@ -2,8 +2,9 @@
2
  #
3
  # Universal AI Data Analyst with:
4
  # - Unchanged analysis & assessment logic
5
- # - Top: Current Assessment / Assessment History (full width, fills the screen)
6
  # - Bottom: New Assessment (files, prompt, actions, voice)
 
7
  # - Fixed Gradio wiring (uses gr.State for history)
8
  # - Triple-quoted progress strings
9
  # - Voice-to-Text via browser Web Speech API
@@ -33,7 +34,7 @@ from settings import (
33
  USE_OPEN_FALLBACKS # noqa: F401
34
  )
35
 
36
- # Try to import optional HIPAA flags; fall back to safe defaults if not defined.
37
  try:
38
  from settings import PHI_MODE, PERSIST_HISTORY, HISTORY_TTL_DAYS, REDACT_BEFORE_LLM, ALLOW_EXTERNAL_PHI
39
  except Exception:
@@ -65,7 +66,7 @@ def _sanitize_text(s: str) -> str:
65
  return re2.sub(r"[\p{C}--[\n\t]]+", "", s)
66
 
67
 
68
- # Conservative PHI redaction patterns (only applied if PHI_MODE & REDACT_BEFORE_LLM are enabled)
69
  PHI_PATTERNS = [
70
  (re.compile(r"\b\d{3}-\d{2}-\d{4}\b"), "[REDACTED_SSN]"),
71
  (re.compile(r"\b\d{9}\b"), "[REDACTED_MRN]"),
@@ -91,7 +92,6 @@ def safe_log(event_name: str, meta: dict | None = None):
91
  meta.pop("raw", None)
92
  log_event(event_name, None, meta)
93
  except Exception:
94
- # Never raise from logging
95
  pass
96
 
97
 
@@ -275,70 +275,60 @@ TERMS_OF_SERVICE_TEXT = load_markdown_text("terms_of_service.md")
275
  # ---------------------- Sleek UI assets (CSS/JS only) ----------------------
276
 
277
  SLEEK_CSS = """
278
- /* Full-bleed, modern look */
279
  :root, body, #root, .gradio-container { height: 100%; }
280
- .gradio-container { padding: 0 !important; }
281
  .block { padding: 0 !important; }
282
 
283
  /* Header */
284
  .header {
285
- padding: 20px 28px;
286
- background: linear-gradient(135deg, #0e1726, #1d2a44 60%, #243a5e);
287
- color: #fff;
288
- display: flex; align-items: center; justify-content: space-between;
289
- gap: 16px;
 
 
 
290
  }
291
- .header h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; font-weight: 600; }
292
- .header .badge { font-size: 12px; opacity: 0.9; background:#ffffff22; padding:6px 10px; border-radius: 999px; }
293
 
294
  /* App body: top (tabs) + bottom (input) */
295
- .app {
296
- display: flex; flex-direction: column;
297
- height: calc(100vh - 72px);
298
- }
299
 
300
- /* Top area: takes remaining space */
301
- .top-area {
302
- flex: 1 1 auto;
303
- padding: 16px;
304
- box-sizing: border-box;
305
- }
306
  .top-card {
307
- height: 100%;
308
- background: #0b1020;
309
- color: #e9edf3;
310
- border-radius: 16px;
311
- border: 1px solid #1c2642;
312
- display: flex; flex-direction: column;
313
- overflow: hidden;
314
  }
315
 
316
- /* Tabs fill available space */
317
  .tabs { flex: 1 1 auto; display: flex; flex-direction: column; }
318
  .tabitem { flex: 1 1 auto; display: flex; flex-direction: column; }
319
  #chatbot_container { flex: 1 1 auto; display: flex; }
320
  #chatbot_container .gr-chatbot { flex: 1 1 auto; height: 100%; }
321
 
322
- /* Bottom input area: sits at bottom, fixed-ish height */
323
- .bottom-area {
324
- flex: 0 0 auto;
325
- padding: 12px 16px 16px 16px;
326
- box-sizing: border-box;
327
- }
328
  .bottom-card {
329
- background: #0b1020;
330
- color: #e9edf3;
331
- border-radius: 16px;
332
- border: 1px solid #1c2642;
333
- padding: 14px;
334
  }
335
- .panel-title { font-size: 14px; font-weight: 600; color: #aeb8cc; margin-bottom: 6px; }
336
- .helper { font-size: 12px; color: #97a3bb; margin-bottom: 8px; }
337
 
 
338
  .actions { display: flex; gap: 8px; }
339
  .actions .gr-button { flex: 1; }
340
- .voice-hint { font-size: 12px; color:#9fb0cc; margin-top: 4px; }
341
- .hr { height: 1px; background: #16203b; margin: 10px 0; }
 
 
 
 
 
 
342
  """
343
 
344
  VOICE_STT_HTML = """
 
2
  #
3
  # Universal AI Data Analyst with:
4
  # - Unchanged analysis & assessment logic
5
+ # - Top: Current Assessment / Assessment History (full width, fills screen)
6
  # - Bottom: New Assessment (files, prompt, actions, voice)
7
+ # - Sleek "ChatGPT-ish" UI polish (soft dark, rounded, green accents)
8
  # - Fixed Gradio wiring (uses gr.State for history)
9
  # - Triple-quoted progress strings
10
  # - Voice-to-Text via browser Web Speech API
 
34
  USE_OPEN_FALLBACKS # noqa: F401
35
  )
36
 
37
+ # Optional HIPAA flags; default to safe, non-breaking values if absent.
38
  try:
39
  from settings import PHI_MODE, PERSIST_HISTORY, HISTORY_TTL_DAYS, REDACT_BEFORE_LLM, ALLOW_EXTERNAL_PHI
40
  except Exception:
 
66
  return re2.sub(r"[\p{C}--[\n\t]]+", "", s)
67
 
68
 
69
+ # Conservative PHI redaction patterns (applied only if PHI_MODE & REDACT_BEFORE_LLM are enabled)
70
  PHI_PATTERNS = [
71
  (re.compile(r"\b\d{3}-\d{2}-\d{4}\b"), "[REDACTED_SSN]"),
72
  (re.compile(r"\b\d{9}\b"), "[REDACTED_MRN]"),
 
92
  meta.pop("raw", None)
93
  log_event(event_name, None, meta)
94
  except Exception:
 
95
  pass
96
 
97
 
 
275
  # ---------------------- Sleek UI assets (CSS/JS only) ----------------------
276
 
277
  SLEEK_CSS = """
278
+ /* Global */
279
  :root, body, #root, .gradio-container { height: 100%; }
280
+ .gradio-container { padding: 0 !important; background: #0e1117; color: #e6e9ef; }
281
  .block { padding: 0 !important; }
282
 
283
  /* Header */
284
  .header {
285
+ padding: 18px 22px;
286
+ background: linear-gradient(180deg, #11161f 0%, #0f141b 100%);
287
+ border-bottom: 1px solid #1e2633;
288
+ display: flex; align-items: center; justify-content: space-between; gap: 12px;
289
+ }
290
+ .header h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .2px; color: #eaf2ee; }
291
+ .header .badge {
292
+ font-size: 12px; background: #1a2a1f; color: #a6e3b1; padding: 6px 10px; border-radius: 999px; border: 1px solid #23402a;
293
  }
 
 
294
 
295
  /* App body: top (tabs) + bottom (input) */
296
+ .app { display: flex; flex-direction: column; height: calc(100vh - 60px); }
 
 
 
297
 
298
+ /* Top area */
299
+ .top-area { flex: 1 1 auto; padding: 12px 12px 0 12px; box-sizing: border-box; }
 
 
 
 
300
  .top-card {
301
+ height: 100%; background: #0f141b; border: 1px solid #1e2633;
302
+ border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
303
+ box-shadow: 0 0 0 1px #0a0d12 inset, 0 8px 20px rgba(0,0,0,.35);
 
 
 
 
304
  }
305
 
306
+ /* Tabs */
307
  .tabs { flex: 1 1 auto; display: flex; flex-direction: column; }
308
  .tabitem { flex: 1 1 auto; display: flex; flex-direction: column; }
309
  #chatbot_container { flex: 1 1 auto; display: flex; }
310
  #chatbot_container .gr-chatbot { flex: 1 1 auto; height: 100%; }
311
 
312
+ /* Bottom input area */
313
+ .bottom-area { flex: 0 0 auto; padding: 10px 12px 12px 12px; box-sizing: border-box; }
 
 
 
 
314
  .bottom-card {
315
+ background: #0f141b; border: 1px solid #1e2633; border-radius: 14px; padding: 12px;
316
+ box-shadow: 0 0 0 1px #0a0d12 inset, 0 8px 20px rgba(0,0,0,.35);
 
 
 
317
  }
318
+ .panel-title { font-size: 13px; font-weight: 600; color: #c9d4cf; margin-bottom: 4px; }
319
+ .helper { font-size: 12px; color: #96a1a7; margin-bottom: 8px; }
320
 
321
+ /* Inputs & actions */
322
  .actions { display: flex; gap: 8px; }
323
  .actions .gr-button { flex: 1; }
324
+ .gr-button.primary { background: #1f8a53 !important; border: 1px solid #2ea36a !important; }
325
+ .gr-button.primary:hover { filter: brightness(1.05); }
326
+
327
+ .voice-hint { font-size: 12px; color: #9fb0cc; margin-top: 4px; }
328
+ .hr { height: 1px; background: #1a2230; margin: 10px 0; }
329
+
330
+ /* Markdown / content */
331
+ .markdown-body { color: #e6e9ef; }
332
  """
333
 
334
  VOICE_STT_HTML = """