ciaochris commited on
Commit
201d311
·
verified ·
1 Parent(s): 4deb026

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -13,7 +13,6 @@ client = Groq(
13
  )
14
 
15
  def get_diagnosis(age, gender, symptoms, medical_history):
16
- # IMPORTANT: This is a simplified example and should not be used for actual medical diagnosis
17
  prompt = f"""
18
  Given the following patient information, provide a preliminary analysis of potential cancer risks.
19
  This is not a definitive diagnosis and should not replace professional medical advice.
@@ -59,27 +58,42 @@ def get_diagnosis(age, gender, symptoms, medical_history):
59
  max_tokens=1500,
60
  )
61
 
62
- response = json.loads(chat_completion.choices[0].message.content)
 
 
 
 
 
 
 
 
 
 
 
63
  return response
64
  except Exception as e:
65
- return {"error": str(e)}
66
 
67
  def format_output(response):
68
  if "error" in response:
69
- return f"An error occurred: {response['error']}"
 
 
 
70
 
71
- output = "Vers3Dynamics HealthScan: Personalized Cancer Risk Insights\n\n"
72
 
73
  output += "Potential Cancer Types:\n"
74
- for cancer in response["potential_cancer_types"]:
75
- output += f"- {cancer['name']} (Risk Level: {cancer['risk_level']})\n {cancer['description']}\n\n"
 
76
 
77
  output += "Recommended Tests:\n"
78
- for test in response["recommended_tests"]:
79
- output += f"- {test['name']}: {test['description']}\n\n"
80
 
81
- output += f"General Advice:\n{response['general_advice']}\n\n"
82
- output += f"DISCLAIMER:\n{response['disclaimer']}"
83
 
84
  return output
85
 
 
13
  )
14
 
15
  def get_diagnosis(age, gender, symptoms, medical_history):
 
16
  prompt = f"""
17
  Given the following patient information, provide a preliminary analysis of potential cancer risks.
18
  This is not a definitive diagnosis and should not replace professional medical advice.
 
58
  max_tokens=1500,
59
  )
60
 
61
+ response_content = chat_completion.choices[0].message.content
62
+
63
+ # Try to parse the JSON response
64
+ try:
65
+ response = json.loads(response_content)
66
+ except json.JSONDecodeError:
67
+ # If JSON parsing fails, return the raw text response
68
+ return {
69
+ "error": "Failed to parse API response as JSON. Raw response:",
70
+ "raw_response": response_content
71
+ }
72
+
73
  return response
74
  except Exception as e:
75
+ return {"error": f"An error occurred while communicating with the API: {str(e)}"}
76
 
77
  def format_output(response):
78
  if "error" in response:
79
+ if "raw_response" in response:
80
+ return f"Error: {response['error']}\n\nRaw API Response:\n{response['raw_response']}"
81
+ else:
82
+ return f"Error: {response['error']}"
83
 
84
+ output = "HealthScan AI: Personalized Cancer Risk Insights\n\n"
85
 
86
  output += "Potential Cancer Types:\n"
87
+ for cancer in response.get("potential_cancer_types", []):
88
+ output += f"- {cancer.get('name', 'N/A')} (Risk Level: {cancer.get('risk_level', 'N/A')})\n"
89
+ output += f" {cancer.get('description', 'No description provided.')}\n\n"
90
 
91
  output += "Recommended Tests:\n"
92
+ for test in response.get("recommended_tests", []):
93
+ output += f"- {test.get('name', 'N/A')}: {test.get('description', 'No description provided.')}\n\n"
94
 
95
+ output += f"General Advice:\n{response.get('general_advice', 'No general advice provided.')}\n\n"
96
+ output += f"DISCLAIMER:\n{response.get('disclaimer', 'No disclaimer provided. This tool is for educational purposes only and should not replace professional medical advice.')}"
97
 
98
  return output
99