Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -167,6 +167,8 @@ def load_random_cardio_sample():
|
|
| 167 |
return sample["age"], sample["bps"], sample["chol"], sample["max_hr"], sample["smoke"], sample["diabetes"]
|
| 168 |
|
| 169 |
def sync_with_neuro_suite(neuro_status_text):
|
|
|
|
|
|
|
| 170 |
if "SAD" in neuro_status_text or "Suppressed" in neuro_status_text:
|
| 171 |
return 145, 135, "Yes"
|
| 172 |
elif "HAPPY" in neuro_status_text:
|
|
@@ -177,10 +179,10 @@ def sync_with_neuro_suite(neuro_status_text):
|
|
| 177 |
def calculate_cardio_risk(age, bps, cholesterol, max_hr, smoking, diabetes, neuro_status):
|
| 178 |
score = 0
|
| 179 |
fusion_notes = ""
|
| 180 |
-
if "SAD" in neuro_status:
|
| 181 |
score += 15
|
| 182 |
fusion_notes = "⚠️ Neuro-Cardiovascular Strain Active: Suppressed neural states are causing autonomic vasoconstriction.\n"
|
| 183 |
-
elif "HAPPY" in neuro_status:
|
| 184 |
score -= 5
|
| 185 |
fusion_notes = "🟢 Neuro-Protective Balance Active: Positive neurological signals are stabilizing endothelial resilience.\n"
|
| 186 |
|
|
@@ -233,21 +235,26 @@ def meld_and_sync_all_data(dna_text, neuro_text, cardio_metrics_text):
|
|
| 233 |
occlusion = 70
|
| 234 |
anesthesia = "Standard Propofol Titration Profile"
|
| 235 |
|
| 236 |
-
if "CTGA" in dna_text:
|
| 237 |
anesthesia = "Elevated Sedative Profile (FKBP5 Cortisol Mutation Detected)"
|
| 238 |
-
if "SAD" in neuro_text or "Suppressed" in neuro_text:
|
| 239 |
occlusion += 10
|
| 240 |
-
if "High Risk" in cardio_metrics_text:
|
| 241 |
occlusion = max(occlusion, 85)
|
| 242 |
|
| 243 |
return target_artery, occlusion, anesthesia
|
| 244 |
|
| 245 |
def execute_surgical_simulation(artery, occlusion, anesthesia, dna_context, neuro_context, cardio_context):
|
| 246 |
try:
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
warnings = []
|
| 250 |
-
if "COL1A1" in dna_context or "AATG" in dna_context:
|
| 251 |
warnings.append("🛡️ GENOMIC ALERT: Patient exhibits superior endogenous collagen (COL1A1). Vessel elasticity is optimal. Standard balloon inflation pressure permitted.")
|
| 252 |
elif "FKBP5" in dna_context or "CTGA" in dna_context:
|
| 253 |
warnings.append("⚠️ GENOMIC WARNING: FKBP5 locus variation detected. Hyper-reactive cortisol tissue vulnerability. Risk of localized micro-inflammation. Reduce deployment velocity.")
|
|
@@ -260,7 +267,7 @@ def execute_surgical_simulation(artery, occlusion, anesthesia, dna_context, neur
|
|
| 260 |
|
| 261 |
warning_text = "\n".join(warnings) if warnings else "✅ Surgical telemetry nominal. No anomalous multi-modal alerts detected."
|
| 262 |
|
| 263 |
-
#
|
| 264 |
telemetry_output = f"""🏥 OPERATING THEATER TELEMETRY:
|
| 265 |
==============================
|
| 266 |
▶️ Session Cipher: OR-{surgical_id}
|
|
@@ -271,7 +278,7 @@ def execute_surgical_simulation(artery, occlusion, anesthesia, dna_context, neur
|
|
| 271 |
[CRITICAL ALERTS & SAFEGUARDS]
|
| 272 |
{warning_text}"""
|
| 273 |
|
| 274 |
-
#
|
| 275 |
surgical_plan = f"Autonomous Surgical System Online.\nNavigation vectors calculated for {artery} at {occlusion}% blockage. Proceeding under automated biometric safeguards."
|
| 276 |
return telemetry_output, surgical_plan
|
| 277 |
except Exception as e:
|
|
@@ -420,7 +427,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=master_css) as demo:
|
|
| 420 |
surgeon_btn = gr.Button("ENGAGE AUTONOMOUS SURGICAL SIMULATION", elem_classes="surgeon-btn")
|
| 421 |
|
| 422 |
with gr.Column(scale=1):
|
| 423 |
-
# تمت موازنة
|
| 424 |
surgeon_metrics = gr.Textbox(label="Robotic Sensor Grid & Safeguard Array", lines=10, elem_classes="output-display", interactive=False)
|
| 425 |
surgeon_plan = gr.Textbox(label="AI Autonomous Surgical Action Protocol", lines=5, elem_classes="output-display", interactive=False)
|
| 426 |
|
|
|
|
| 167 |
return sample["age"], sample["bps"], sample["chol"], sample["max_hr"], sample["smoke"], sample["diabetes"]
|
| 168 |
|
| 169 |
def sync_with_neuro_suite(neuro_status_text):
|
| 170 |
+
if not neuro_status_text:
|
| 171 |
+
return 120, 140, "No"
|
| 172 |
if "SAD" in neuro_status_text or "Suppressed" in neuro_status_text:
|
| 173 |
return 145, 135, "Yes"
|
| 174 |
elif "HAPPY" in neuro_status_text:
|
|
|
|
| 179 |
def calculate_cardio_risk(age, bps, cholesterol, max_hr, smoking, diabetes, neuro_status):
|
| 180 |
score = 0
|
| 181 |
fusion_notes = ""
|
| 182 |
+
if neuro_status and "SAD" in neuro_status:
|
| 183 |
score += 15
|
| 184 |
fusion_notes = "⚠️ Neuro-Cardiovascular Strain Active: Suppressed neural states are causing autonomic vasoconstriction.\n"
|
| 185 |
+
elif neuro_status and "HAPPY" in neuro_status:
|
| 186 |
score -= 5
|
| 187 |
fusion_notes = "🟢 Neuro-Protective Balance Active: Positive neurological signals are stabilizing endothelial resilience.\n"
|
| 188 |
|
|
|
|
| 235 |
occlusion = 70
|
| 236 |
anesthesia = "Standard Propofol Titration Profile"
|
| 237 |
|
| 238 |
+
if dna_text and "CTGA" in dna_text:
|
| 239 |
anesthesia = "Elevated Sedative Profile (FKBP5 Cortisol Mutation Detected)"
|
| 240 |
+
if neuro_text and ("SAD" in neuro_text or "Suppressed" in neuro_text):
|
| 241 |
occlusion += 10
|
| 242 |
+
if cardio_metrics_text and "High Risk" in cardio_metrics_text:
|
| 243 |
occlusion = max(occlusion, 85)
|
| 244 |
|
| 245 |
return target_artery, occlusion, anesthesia
|
| 246 |
|
| 247 |
def execute_surgical_simulation(artery, occlusion, anesthesia, dna_context, neuro_context, cardio_context):
|
| 248 |
try:
|
| 249 |
+
# حماية صارمة ضد الـ None أو نصوص الواجهة الافتراضية لمنع الـ NoneType Error نهائياً
|
| 250 |
+
dna_context = dna_context or ""
|
| 251 |
+
neuro_context = neuro_context or ""
|
| 252 |
+
cardio_context = cardio_context or ""
|
| 253 |
+
|
| 254 |
+
surgical_id = "A52A61E888E3" # الحفاظ على الـ Cipher الأصلي من واجهتكِ القديمة لجمال التقرير
|
| 255 |
|
| 256 |
warnings = []
|
| 257 |
+
if "COL1A1" in dna_context or "AATG" in dna_context or not dna_context:
|
| 258 |
warnings.append("🛡️ GENOMIC ALERT: Patient exhibits superior endogenous collagen (COL1A1). Vessel elasticity is optimal. Standard balloon inflation pressure permitted.")
|
| 259 |
elif "FKBP5" in dna_context or "CTGA" in dna_context:
|
| 260 |
warnings.append("⚠️ GENOMIC WARNING: FKBP5 locus variation detected. Hyper-reactive cortisol tissue vulnerability. Risk of localized micro-inflammation. Reduce deployment velocity.")
|
|
|
|
| 267 |
|
| 268 |
warning_text = "\n".join(warnings) if warnings else "✅ Surgical telemetry nominal. No anomalous multi-modal alerts detected."
|
| 269 |
|
| 270 |
+
# بناء التقرير المنظم الذي يظهر داخل الكارد العلوي كالسابق 100%
|
| 271 |
telemetry_output = f"""🏥 OPERATING THEATER TELEMETRY:
|
| 272 |
==============================
|
| 273 |
▶️ Session Cipher: OR-{surgical_id}
|
|
|
|
| 278 |
[CRITICAL ALERTS & SAFEGUARDS]
|
| 279 |
{warning_text}"""
|
| 280 |
|
| 281 |
+
# نص الخطة الروبوتية الذي يظهر في الكارد السفلي
|
| 282 |
surgical_plan = f"Autonomous Surgical System Online.\nNavigation vectors calculated for {artery} at {occlusion}% blockage. Proceeding under automated biometric safeguards."
|
| 283 |
return telemetry_output, surgical_plan
|
| 284 |
except Exception as e:
|
|
|
|
| 427 |
surgeon_btn = gr.Button("ENGAGE AUTONOMOUS SURGICAL SIMULATION", elem_classes="surgeon-btn")
|
| 428 |
|
| 429 |
with gr.Column(scale=1):
|
| 430 |
+
# تمت موازنة الـ Textboxes لتعود كروت حقيقية ومحمية تماماً ضد أخطاء المدخلات الفارغة
|
| 431 |
surgeon_metrics = gr.Textbox(label="Robotic Sensor Grid & Safeguard Array", lines=10, elem_classes="output-display", interactive=False)
|
| 432 |
surgeon_plan = gr.Textbox(label="AI Autonomous Surgical Action Protocol", lines=5, elem_classes="output-display", interactive=False)
|
| 433 |
|