Ali2206 commited on
Commit
0e8f161
·
verified ·
1 Parent(s): 392b971

Update analysis.py

Browse files
Files changed (1) hide show
  1. analysis.py +15 -2
analysis.py CHANGED
@@ -46,12 +46,25 @@ async def create_alert(patient_id: str, risk_data: dict):
46
  }
47
 
48
  try:
 
49
  await alerts_collection.insert_one(alert_doc)
50
- await broadcast_notification(alert_doc["notification"])
 
 
 
 
 
 
 
 
 
 
 
 
51
  logger.warning(f"⚠️ Created suicide risk alert for patient {patient_id}")
52
  return alert_doc
53
  except Exception as e:
54
- logger.error(f"Failed to create alert for patient {patient_id}: {str(e)}")
55
  raise
56
 
57
  async def analyze_patient_report(
 
46
  }
47
 
48
  try:
49
+ # Insert into database
50
  await alerts_collection.insert_one(alert_doc)
51
+
52
+ # For Hugging Face Spaces, use their event system instead of raw WebSocket
53
+ if os.getenv('SPACES') == '1':
54
+ from gradio import EventSource
55
+ EventSource.emit(
56
+ event="notification",
57
+ data=json.dumps(alert_doc["notification"]),
58
+ broadcast=True
59
+ )
60
+ else:
61
+ # Local development with regular WebSocket
62
+ await broadcast_notification(alert_doc["notification"])
63
+
64
  logger.warning(f"⚠️ Created suicide risk alert for patient {patient_id}")
65
  return alert_doc
66
  except Exception as e:
67
+ logger.error(f"Failed to create alert: {str(e)}")
68
  raise
69
 
70
  async def analyze_patient_report(