yashbyname commited on
Commit
a32bf71
·
verified ·
1 Parent(s): 1b6df32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -80,7 +80,7 @@ def submit_query(session_id, query):
80
  raise
81
 
82
 
83
- def extract_json_from_answer(answer):
84
  """Extract and clean JSON from the LLM response"""
85
  try:
86
  # First try to parse the answer directly
@@ -91,10 +91,10 @@ def extract_json_from_answer(answer):
91
  try:
92
  # If that fails, try to find JSON content and parse it
93
  start_idx = answer.find('{')
94
- end_idx = answer.rfind('}') + 1
95
  if start_idx != -1 and end_idx != 0:
96
  json_str = answer[start_idx:end_idx]
97
-
98
  return json.loads(json_str)
99
  except (json.JSONDecodeError, ValueError):
100
  logger.error("Failed to parse JSON from response")
@@ -179,7 +179,7 @@ def gradio_interface(patient_info, image):
179
  "status": "error"
180
  }, indent=2)
181
 
182
- classes = ["Alzheimer's", "Stroke", "Tumor", "Normal"]
183
  # Process image if provided
184
  image_analysis = None
185
  if image is not None:
@@ -208,7 +208,7 @@ def gradio_interface(patient_info, image):
208
  raise ValueError("Invalid response structure from LLM")
209
 
210
  # Extract and clean JSON from the response
211
- json_data = extract_json_from_answer(llm_response['data']['answer'])
212
  logger.info(f"llm_response: {llm_response}")
213
  logger.info(f"llm_response[data]: {llm_response['data']}")
214
  logger.info(f"llm_response[data][answer]: {llm_response['data']['answer']}")
 
80
  raise
81
 
82
 
83
+ def extract_json_from_answer(answer, image_analysis):
84
  """Extract and clean JSON from the LLM response"""
85
  try:
86
  # First try to parse the answer directly
 
91
  try:
92
  # If that fails, try to find JSON content and parse it
93
  start_idx = answer.find('{')
94
+ end_idx = answer.rfind('}')
95
  if start_idx != -1 and end_idx != 0:
96
  json_str = answer[start_idx:end_idx]
97
+ json_str += f"image_analysis: ['prediction': {image_analysis['prediction']}, 'confidence': {image_analysis['confidence']}%.]
98
  return json.loads(json_str)
99
  except (json.JSONDecodeError, ValueError):
100
  logger.error("Failed to parse JSON from response")
 
179
  "status": "error"
180
  }, indent=2)
181
 
182
+ classes = ["Alzheimer's", "Normal", "Stroke", "Tumor"]
183
  # Process image if provided
184
  image_analysis = None
185
  if image is not None:
 
208
  raise ValueError("Invalid response structure from LLM")
209
 
210
  # Extract and clean JSON from the response
211
+ json_data = extract_json_from_answer(llm_response['data']['answer'], image_analysis)
212
  logger.info(f"llm_response: {llm_response}")
213
  logger.info(f"llm_response[data]: {llm_response['data']}")
214
  logger.info(f"llm_response[data][answer]: {llm_response['data']['answer']}")