Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -186,7 +186,7 @@ def create_chat_session():
|
|
186 |
|
187 |
logger.info("Creating chat session...")
|
188 |
response = requests.post(create_session_url, headers=create_session_headers, json=create_session_body)
|
189 |
-
response.raise_for_status()
|
190 |
|
191 |
response_data = response.json()
|
192 |
logger.info(f"Session created successfully: {json.dumps(response_data, indent=2)}")
|
@@ -249,16 +249,24 @@ def gradio_interface(patient_info, query_type):
|
|
249 |
# Navigate the response structure with detailed logging
|
250 |
logger.info(f"Processing LLM response: {json.dumps(llm_response, indent=2)}")
|
251 |
|
252 |
-
|
253 |
-
|
|
|
254 |
return f"Error: Unexpected response structure\nFull response: {json.dumps(llm_response, indent=2)}"
|
255 |
|
256 |
-
|
257 |
-
if not
|
258 |
-
logger.error("No
|
259 |
-
return f"Error: No
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
-
response = f"Patient Info: {patient_info}\nQuery Type: {query_type}\n\nLLM Response:\n{message}"
|
262 |
return response
|
263 |
|
264 |
except Exception as e:
|
|
|
186 |
|
187 |
logger.info("Creating chat session...")
|
188 |
response = requests.post(create_session_url, headers=create_session_headers, json=create_session_body)
|
189 |
+
response.raise_for_status()
|
190 |
|
191 |
response_data = response.json()
|
192 |
logger.info(f"Session created successfully: {json.dumps(response_data, indent=2)}")
|
|
|
249 |
# Navigate the response structure with detailed logging
|
250 |
logger.info(f"Processing LLM response: {json.dumps(llm_response, indent=2)}")
|
251 |
|
252 |
+
# Check for answer in the correct field
|
253 |
+
if 'data' not in llm_response or 'answer' not in llm_response['data']:
|
254 |
+
logger.error("Response missing required fields")
|
255 |
return f"Error: Unexpected response structure\nFull response: {json.dumps(llm_response, indent=2)}"
|
256 |
|
257 |
+
answer = llm_response['data']['answer']
|
258 |
+
if not answer:
|
259 |
+
logger.error("No answer found in response data")
|
260 |
+
return f"Error: No answer in response\nFull response: {json.dumps(llm_response, indent=2)}"
|
261 |
+
|
262 |
+
# Format the response
|
263 |
+
response = f"Patient Info: {patient_info}\n\nQuery Type: {query_type}\n\nAnalysis:\n{answer}"
|
264 |
+
|
265 |
+
# Add completion metrics if available
|
266 |
+
if 'metrics' in llm_response['data']:
|
267 |
+
metrics = llm_response['data']['metrics']
|
268 |
+
response += f"\n\nProcessing Time: {metrics.get('totalTimeSec', 'N/A')} seconds"
|
269 |
|
|
|
270 |
return response
|
271 |
|
272 |
except Exception as e:
|