petter2025 commited on
Commit
5d9bea2
·
verified ·
1 Parent(s): 8767cd1

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +63 -135
hf_demo.py CHANGED
@@ -1,9 +1,5 @@
1
- # ARF 3.3.9 DEMO WITH FIXED HTML RENDERING BUGS
2
- # CRITICAL FIXES APPLIED:
3
- # 1. All HTML content now uses gr.HTML() instead of gr.Markdown()
4
- # 2. Proper Gradio container nesting
5
- # 3. Fixed CSS class conflicts
6
- # 4. Enhanced mobile responsiveness
7
 
8
  import gradio as gr
9
  import time
@@ -125,7 +121,7 @@ def detect_unified_arf() -> Dict[str, Any]:
125
  'enterprise_ready': True
126
  }
127
 
128
- # Get unified ARF status (SINGLE SOURCE OF TRUTH)
129
  ARF_UNIFIED_STATUS = detect_unified_arf()
130
 
131
  print(f"\n{'='*80}")
@@ -140,25 +136,10 @@ print(f"{'='*80}\n")
140
  arf_engine = EnhancedARFEngine()
141
  psychology_engine = EnhancedPsychologyEngine()
142
 
143
- # ============== ENHANCED CSS WITH FIXED CLASSES ==============
144
  ENHANCED_CSS = """
145
- :root {
146
- /* Mathematical Color Psychology */
147
- --mathematical-blue: #2196F3;
148
- --mathematical-green: #4CAF50;
149
- --mathematical-orange: #FF9800;
150
- --mathematical-red: #F44336;
151
- --mathematical-purple: #9C27B0;
152
- }
153
-
154
- /* FIXED: Mathematical Badges with proper HTML rendering */
155
  .arf-real-badge {
156
- background: linear-gradient(135deg,
157
- #4CAF50 0%,
158
- #2E7D32 25%,
159
- #1B5E20 50%,
160
- #0D47A1 100%
161
- );
162
  color: white;
163
  padding: 10px 22px;
164
  border-radius: 25px;
@@ -174,12 +155,7 @@ ENHANCED_CSS = """
174
  }
175
 
176
  .arf-sim-badge {
177
- background: linear-gradient(135deg,
178
- #FF9800 0%,
179
- #F57C00 25%,
180
- #E65100 50%,
181
- #BF360C 100%
182
- );
183
  color: white;
184
  padding: 10px 22px;
185
  border-radius: 25px;
@@ -194,21 +170,11 @@ ENHANCED_CSS = """
194
  }
195
 
196
  @keyframes pulse-mathematical {
197
- 0% {
198
- box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7),
199
- 0 6px 20px rgba(76, 175, 80, 0.4);
200
- }
201
- 70% {
202
- box-shadow: 0 0 0 15px rgba(76, 175, 80, 0),
203
- 0 6px 20px rgba(76, 175, 80, 0.4);
204
- }
205
- 100% {
206
- box-shadow: 0 0 0 0 rgba(76, 175, 80, 0),
207
- 0 6px 20px rgba(76, 175, 80, 0.4);
208
- }
209
  }
210
 
211
- /* FIXED: Mathematical Gate Visualization */
212
  .mathematical-gate {
213
  width: 70px;
214
  height: 70px;
@@ -225,19 +191,9 @@ ENHANCED_CSS = """
225
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
226
  }
227
 
228
- .gate-passed {
229
- background: linear-gradient(135deg, #4CAF50, #2E7D32);
230
- animation: gate-success-mathematical 0.7s ease-out;
231
- }
232
-
233
- .gate-failed {
234
- background: linear-gradient(135deg, #F44336, #D32F2F);
235
- animation: gate-fail-mathematical 0.7s ease-out;
236
- }
237
-
238
- .gate-pending {
239
- background: linear-gradient(135deg, #9E9E9E, #616161);
240
- }
241
 
242
  .gate-container {
243
  display: flex;
@@ -255,7 +211,6 @@ ENHANCED_CSS = """
255
  border-radius: 2px;
256
  }
257
 
258
- /* FIXED: Mathematical Cards */
259
  .mathematical-card {
260
  border-radius: 15px;
261
  padding: 25px;
@@ -283,48 +238,18 @@ ENHANCED_CSS = """
283
  background: linear-gradient(145deg, #FFF8E1, #FFFFFF);
284
  }
285
 
286
- /* FIXED: Responsive Design */
287
  @media (max-width: 768px) {
288
- .gradio-container {
289
- padding: 10px !important;
290
- }
291
-
292
- .arf-real-badge, .arf-sim-badge {
293
- padding: 6px 14px;
294
- font-size: 12px;
295
- }
296
-
297
- .mathematical-gate {
298
- width: 50px;
299
- height: 50px;
300
- font-size: 18px;
301
- }
302
-
303
- .gate-line {
304
- width: 20px;
305
- }
306
-
307
- .mathematical-card {
308
- padding: 15px;
309
- margin: 10px 0;
310
- }
311
  }
312
 
313
  @media (max-width: 480px) {
314
- .gradio-container {
315
- padding: 5px !important;
316
- }
317
-
318
- .arf-real-badge, .arf-sim-badge {
319
- padding: 4px 10px;
320
- font-size: 11px;
321
- }
322
-
323
- .mathematical-gate {
324
- width: 40px;
325
- height: 40px;
326
- font-size: 16px;
327
- }
328
  }
329
  """
330
 
@@ -430,7 +355,7 @@ class EnhancedDemoState:
430
  # Initialize demo state
431
  demo_state = EnhancedDemoState(ARF_UNIFIED_STATUS)
432
 
433
- # ============== GRADIO INTERFACE WITH FIXED HTML RENDERING ==============
434
  def create_enhanced_demo():
435
  """Create enhanced demo with fixed HTML rendering bugs"""
436
 
@@ -440,14 +365,11 @@ def create_enhanced_demo():
440
 
441
  with gr.Blocks(
442
  title=f"ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication",
443
- theme=gr.themes.Soft(
444
- primary_hue="blue",
445
- secondary_hue="orange"
446
- ),
447
  css=ENHANCED_CSS
448
  ) as demo:
449
 
450
- # ===== FIXED: HEADER USING gr.HTML() =====
451
  gr.HTML(f"""
452
  <div style="background: linear-gradient(135deg, #0D47A1, #1565C0); color: white; padding: 30px; border-radius: 15px; margin-bottom: 30px; box-shadow: 0 10px 30px rgba(13, 71, 161, 0.4); position: relative; overflow: hidden;">
453
  <div style="position: absolute; top: 0; right: 0; width: 300px; height: 300px; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);"></div>
@@ -477,7 +399,7 @@ def create_enhanced_demo():
477
  </div>
478
  """)
479
 
480
- # ===== FIXED: METRICS WITH PROPER CONTAINERS =====
481
  with gr.Row():
482
  metrics = [
483
  ("92%", "Incident Prevention", "Bayesian confidence: 95%", "#4CAF50", "📊"),
@@ -499,7 +421,7 @@ def create_enhanced_demo():
499
  </div>
500
  """)
501
 
502
- # ===== FIXED: SECTION HEADERS =====
503
  gr.HTML("""
504
  <div style="margin: 30px 0 20px 0;">
505
  <h2 style="font-size: 1.8em; color: #0D47A1; margin-bottom: 10px;">🧮 Mathematical Execution Authority Demo</h2>
@@ -540,7 +462,7 @@ def create_enhanced_demo():
540
  test_btn = gr.Button("⚡ Test Mathematical Assessment", variant="primary", scale=2)
541
  trial_btn = gr.Button("🎁 Generate Mathematical Trial", variant="secondary", scale=1)
542
 
543
- # ===== FIXED: LICENSE DISPLAY =====
544
  with gr.Column(scale=1):
545
  license_display = gr.HTML(f"""
546
  <div class="mathematical-card license-oss">
@@ -565,7 +487,7 @@ def create_enhanced_demo():
565
  </div>
566
  """)
567
 
568
- # ===== FIXED: RESULTS PANELS =====
569
  with gr.Row():
570
  with gr.Column(scale=1):
571
  oss_results = gr.HTML("""
@@ -829,10 +751,9 @@ def create_enhanced_demo():
829
  gates_visualization = ""
830
  for i in range(total_gates):
831
  gate_class = "gate-passed" if i < gates_passed else "gate-failed"
832
- gates_visualization += f"""
833
- <div class="mathematical-gate {gate_class}">{i+1}</div>
834
- {'<div class="gate-line"></div>' if i < total_gates-1 else ''}
835
- """
836
 
837
  gates_html = f"""
838
  <div style="font-size: 14px; color: #666; margin-bottom: 15px; font-weight: 600;">
@@ -931,8 +852,8 @@ def create_enhanced_demo():
931
  </div>
932
  """
933
 
934
- # History
935
- history_rows = ""
936
  for entry in demo_state.action_history:
937
  risk_text = format_mathematical_risk(entry['risk_score'])
938
  confidence_text = f"{entry.get('confidence', 0.8):.0%}"
@@ -947,7 +868,7 @@ def create_enhanced_demo():
947
  "BLOCKED": "❌"
948
  }.get(entry['gate_decision'], "⚡")
949
 
950
- history_rows += f"""
951
  <tr>
952
  <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['time']}</td>
953
  <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['action'][:35]}...</td>
@@ -958,35 +879,42 @@ def create_enhanced_demo():
958
  <td style="padding: 12px; border-bottom: 1px solid #eee; font-size: 16px;">{decision_emoji}</td>
959
  <td style="padding: 12px; border-bottom: 1px solid #eee; text-align: center; font-size: 16px;">{arf_emoji}</td>
960
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
961
  """
962
 
 
963
  history_html = f"""
964
  <div style="border: 1px solid #E0E0E0; border-radius: 15px; padding: 20px; background: #fafafa; box-shadow: 0 8px 30px rgba(0,0,0,0.08); margin-top: 20px;">
965
  <h4 style="margin-top: 0; margin-bottom: 15px; color: #333;">📊 Mathematical Action History</h4>
966
  <div style="overflow-x: auto;">
967
- <table style="width: 100%; border-collapse: collapse; font-size: 13px; min-width: 600px;">
968
- <thead>
969
- <tr style="background: #f5f5f5;">
970
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Time</th>
971
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Action</th>
972
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Risk</th>
973
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Confidence</th>
974
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">License</th>
975
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Gates</th>
976
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Decision</th>
977
- <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">ARF</th>
978
- </tr>
979
- </thead>
980
- <tbody>
981
- {history_rows if history_rows else """
982
- <tr>
983
- <td colspan="8" style="text-align: center; padding: 40px; color: #999; font-style: italic;">
984
- No mathematical assessments yet. Test an action to see Bayesian analysis in action.
985
- </td>
986
- </tr>
987
- """}
988
- </tbody>
989
- </table>
990
  </div>
991
  </div>
992
  """
 
1
+ # COMPLETE FIXED hf_demo.py with all syntax errors resolved
2
+ # ARF 3.3.9 DEMO WITH FIXED HTML RENDERING AND SYNTAX ERRORS
 
 
 
 
3
 
4
  import gradio as gr
5
  import time
 
121
  'enterprise_ready': True
122
  }
123
 
124
+ # Get unified ARF status
125
  ARF_UNIFIED_STATUS = detect_unified_arf()
126
 
127
  print(f"\n{'='*80}")
 
136
  arf_engine = EnhancedARFEngine()
137
  psychology_engine = EnhancedPsychologyEngine()
138
 
139
+ # ============== ENHANCED CSS ==============
140
  ENHANCED_CSS = """
 
 
 
 
 
 
 
 
 
 
141
  .arf-real-badge {
142
+ background: linear-gradient(135deg, #4CAF50, #2E7D32, #1B5E20, #0D47A1);
 
 
 
 
 
143
  color: white;
144
  padding: 10px 22px;
145
  border-radius: 25px;
 
155
  }
156
 
157
  .arf-sim-badge {
158
+ background: linear-gradient(135deg, #FF9800, #F57C00, #E65100, #BF360C);
 
 
 
 
 
159
  color: white;
160
  padding: 10px 22px;
161
  border-radius: 25px;
 
170
  }
171
 
172
  @keyframes pulse-mathematical {
173
+ 0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7), 0 6px 20px rgba(76, 175, 80, 0.4); }
174
+ 70% { box-shadow: 0 0 0 15px rgba(76, 175, 80, 0), 0 6px 20px rgba(76, 175, 80, 0.4); }
175
+ 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0), 0 6px 20px rgba(76, 175, 80, 0.4); }
 
 
 
 
 
 
 
 
 
176
  }
177
 
 
178
  .mathematical-gate {
179
  width: 70px;
180
  height: 70px;
 
191
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
192
  }
193
 
194
+ .gate-passed { background: linear-gradient(135deg, #4CAF50, #2E7D32); }
195
+ .gate-failed { background: linear-gradient(135deg, #F44336, #D32F2F); }
196
+ .gate-pending { background: linear-gradient(135deg, #9E9E9E, #616161); }
 
 
 
 
 
 
 
 
 
 
197
 
198
  .gate-container {
199
  display: flex;
 
211
  border-radius: 2px;
212
  }
213
 
 
214
  .mathematical-card {
215
  border-radius: 15px;
216
  padding: 25px;
 
238
  background: linear-gradient(145deg, #FFF8E1, #FFFFFF);
239
  }
240
 
 
241
  @media (max-width: 768px) {
242
+ .gradio-container { padding: 10px !important; }
243
+ .arf-real-badge, .arf-sim-badge { padding: 6px 14px; font-size: 12px; }
244
+ .mathematical-gate { width: 50px; height: 50px; font-size: 18px; }
245
+ .gate-line { width: 20px; }
246
+ .mathematical-card { padding: 15px; margin: 10px 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
 
249
  @media (max-width: 480px) {
250
+ .gradio-container { padding: 5px !important; }
251
+ .arf-real-badge, .arf-sim-badge { padding: 4px 10px; font-size: 11px; }
252
+ .mathematical-gate { width: 40px; height: 40px; font-size: 16px; }
 
 
 
 
 
 
 
 
 
 
 
253
  }
254
  """
255
 
 
355
  # Initialize demo state
356
  demo_state = EnhancedDemoState(ARF_UNIFIED_STATUS)
357
 
358
+ # ============== GRADIO INTERFACE ==============
359
  def create_enhanced_demo():
360
  """Create enhanced demo with fixed HTML rendering bugs"""
361
 
 
365
 
366
  with gr.Blocks(
367
  title=f"ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication",
368
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="orange"),
 
 
 
369
  css=ENHANCED_CSS
370
  ) as demo:
371
 
372
+ # ===== HEADER =====
373
  gr.HTML(f"""
374
  <div style="background: linear-gradient(135deg, #0D47A1, #1565C0); color: white; padding: 30px; border-radius: 15px; margin-bottom: 30px; box-shadow: 0 10px 30px rgba(13, 71, 161, 0.4); position: relative; overflow: hidden;">
375
  <div style="position: absolute; top: 0; right: 0; width: 300px; height: 300px; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);"></div>
 
399
  </div>
400
  """)
401
 
402
+ # ===== METRICS =====
403
  with gr.Row():
404
  metrics = [
405
  ("92%", "Incident Prevention", "Bayesian confidence: 95%", "#4CAF50", "📊"),
 
421
  </div>
422
  """)
423
 
424
+ # ===== SECTION HEADER =====
425
  gr.HTML("""
426
  <div style="margin: 30px 0 20px 0;">
427
  <h2 style="font-size: 1.8em; color: #0D47A1; margin-bottom: 10px;">🧮 Mathematical Execution Authority Demo</h2>
 
462
  test_btn = gr.Button("⚡ Test Mathematical Assessment", variant="primary", scale=2)
463
  trial_btn = gr.Button("🎁 Generate Mathematical Trial", variant="secondary", scale=1)
464
 
465
+ # ===== LICENSE DISPLAY =====
466
  with gr.Column(scale=1):
467
  license_display = gr.HTML(f"""
468
  <div class="mathematical-card license-oss">
 
487
  </div>
488
  """)
489
 
490
+ # ===== RESULTS PANELS =====
491
  with gr.Row():
492
  with gr.Column(scale=1):
493
  oss_results = gr.HTML("""
 
751
  gates_visualization = ""
752
  for i in range(total_gates):
753
  gate_class = "gate-passed" if i < gates_passed else "gate-failed"
754
+ gates_visualization += f'<div class="mathematical-gate {gate_class}">{i+1}</div>'
755
+ if i < total_gates - 1:
756
+ gates_visualization += '<div class="gate-line"></div>'
 
757
 
758
  gates_html = f"""
759
  <div style="font-size: 14px; color: #666; margin-bottom: 15px; font-weight: 600;">
 
852
  </div>
853
  """
854
 
855
+ # Build history rows
856
+ history_rows_html = ""
857
  for entry in demo_state.action_history:
858
  risk_text = format_mathematical_risk(entry['risk_score'])
859
  confidence_text = f"{entry.get('confidence', 0.8):.0%}"
 
868
  "BLOCKED": "❌"
869
  }.get(entry['gate_decision'], "⚡")
870
 
871
+ history_rows_html += f'''
872
  <tr>
873
  <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['time']}</td>
874
  <td style="padding: 12px; border-bottom: 1px solid #eee; color: #555; font-size: 13px;">{entry['action'][:35]}...</td>
 
879
  <td style="padding: 12px; border-bottom: 1px solid #eee; font-size: 16px;">{decision_emoji}</td>
880
  <td style="padding: 12px; border-bottom: 1px solid #eee; text-align: center; font-size: 16px;">{arf_emoji}</td>
881
  </tr>
882
+ '''
883
+
884
+ # Build history table
885
+ if history_rows_html:
886
+ history_table = f"""
887
+ <table style="width: 100%; border-collapse: collapse; font-size: 13px; min-width: 600px;">
888
+ <thead>
889
+ <tr style="background: #f5f5f5;">
890
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Time</th>
891
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Action</th>
892
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Risk</th>
893
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Confidence</th>
894
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">License</th>
895
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Gates</th>
896
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">Decision</th>
897
+ <th style="padding: 12px; border-bottom: 2px solid #E0E0E0; text-align: left;">ARF</th>
898
+ </tr>
899
+ </thead>
900
+ <tbody>
901
+ {history_rows_html}
902
+ </tbody>
903
+ </table>
904
+ """
905
+ else:
906
+ history_table = """
907
+ <div style="text-align: center; padding: 40px; color: #999; font-style: italic;">
908
+ No mathematical assessments yet. Test an action to see Bayesian analysis in action.
909
+ </div>
910
  """
911
 
912
+ # Final history HTML
913
  history_html = f"""
914
  <div style="border: 1px solid #E0E0E0; border-radius: 15px; padding: 20px; background: #fafafa; box-shadow: 0 8px 30px rgba(0,0,0,0.08); margin-top: 20px;">
915
  <h4 style="margin-top: 0; margin-bottom: 15px; color: #333;">📊 Mathematical Action History</h4>
916
  <div style="overflow-x: auto;">
917
+ {history_table}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
918
  </div>
919
  </div>
920
  """