Siyad798 commited on
Commit
5e1e02b
·
verified ·
1 Parent(s): a8fdc22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -51,7 +51,6 @@ def ingest_data():
51
  try:
52
  driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USERNAME, NEO4J_PASSWORD))
53
 
54
- # PrimeKG Subset Data
55
  prime_kg_data = [
56
  ("Ischemic Stroke", "associated_with", "Hypertension"),
57
  ("Ischemic Stroke", "associated_with", "Atrial Fibrillation"),
@@ -79,7 +78,7 @@ def ingest_data():
79
  """
80
 
81
  with driver.session() as session:
82
- session.run("MATCH (n) DETACH DELETE n") # Reset DB for demo
83
  session.run(query, data=prime_kg_data)
84
 
85
  # Unstructured Guidelines Data
@@ -110,7 +109,7 @@ def ingest_data():
110
  except Exception as e:
111
  print(f"❌ KG Initialization Failed: {e}")
112
 
113
- # Run ingestion immediately on startup
114
  ingest_data()
115
 
116
  # ==========================================
@@ -128,13 +127,11 @@ def detect_stroke_type(image_path: str) -> str:
128
 
129
  try:
130
  client = Client(HF_SPACE_URL)
131
- # Call the remote API
132
  result = client.predict(
133
  files=[handle_file(image_path)],
134
  api_name="/predict"
135
  )
136
 
137
- # Robust parsing for Gradio returns
138
  ai_output = {}
139
  if isinstance(result, (list, tuple)) and len(result) > 1:
140
  json_data = result[1]
@@ -242,7 +239,6 @@ def synthesizer_node(state: AgentState):
242
  response = llm.invoke(prompt)
243
  return {"final_report": response.content}
244
 
245
- # Build Graph
246
  workflow = StateGraph(AgentState)
247
  workflow.add_node("detector", detector_node)
248
  workflow.add_node("advisor", advisor_node)
@@ -271,7 +267,7 @@ def predict_stroke_report(uploaded_file, patient_context_input):
271
  try:
272
  # Run Graph
273
  for event in app.stream(inputs, stream_mode="values"):
274
- pass # Exhaust stream
275
  final_state = event
276
  final_report_content = final_state.get("final_report", "Error generating report.")
277
  except Exception as e:
@@ -279,12 +275,10 @@ def predict_stroke_report(uploaded_file, patient_context_input):
279
 
280
  return final_report_content
281
 
282
- # Define Theme
283
  custom_theme = gr.themes.Soft(primary_hue="emerald", secondary_hue="neutral")
284
 
285
- # Launch App
286
- # FIX: Removed title="" from Blocks() to ensure compatibility.
287
- with gr.Blocks(theme=custom_theme) as demo:
288
  gr.Markdown("# 🧠 AI Stroke Diagnosis & Guideline Agent")
289
  gr.Markdown("Integrates Vision AI (DenseNet) + Knowledge Graph (Neo4j) + LLM (Azure OpenAI)")
290
 
 
51
  try:
52
  driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USERNAME, NEO4J_PASSWORD))
53
 
 
54
  prime_kg_data = [
55
  ("Ischemic Stroke", "associated_with", "Hypertension"),
56
  ("Ischemic Stroke", "associated_with", "Atrial Fibrillation"),
 
78
  """
79
 
80
  with driver.session() as session:
81
+ session.run("MATCH (n) DETACH DELETE n")
82
  session.run(query, data=prime_kg_data)
83
 
84
  # Unstructured Guidelines Data
 
109
  except Exception as e:
110
  print(f"❌ KG Initialization Failed: {e}")
111
 
112
+ # Run ingestion
113
  ingest_data()
114
 
115
  # ==========================================
 
127
 
128
  try:
129
  client = Client(HF_SPACE_URL)
 
130
  result = client.predict(
131
  files=[handle_file(image_path)],
132
  api_name="/predict"
133
  )
134
 
 
135
  ai_output = {}
136
  if isinstance(result, (list, tuple)) and len(result) > 1:
137
  json_data = result[1]
 
239
  response = llm.invoke(prompt)
240
  return {"final_report": response.content}
241
 
 
242
  workflow = StateGraph(AgentState)
243
  workflow.add_node("detector", detector_node)
244
  workflow.add_node("advisor", advisor_node)
 
267
  try:
268
  # Run Graph
269
  for event in app.stream(inputs, stream_mode="values"):
270
+ pass
271
  final_state = event
272
  final_report_content = final_state.get("final_report", "Error generating report.")
273
  except Exception as e:
 
275
 
276
  return final_report_content
277
 
 
278
  custom_theme = gr.themes.Soft(primary_hue="emerald", secondary_hue="neutral")
279
 
280
+ # Since we updated the SDK version to 5.0.0, the theme argument is now valid.
281
+ with gr.Blocks(theme=custom_theme, title="Stroke Agent AI") as demo:
 
282
  gr.Markdown("# 🧠 AI Stroke Diagnosis & Guideline Agent")
283
  gr.Markdown("Integrates Vision AI (DenseNet) + Knowledge Graph (Neo4j) + LLM (Azure OpenAI)")
284