Spaces:
Sleeping
Sleeping
ogegadavis254
commited on
Commit
•
ebd3bc8
1
Parent(s):
baea6e3
Update app.py
Browse files
app.py
CHANGED
@@ -78,7 +78,40 @@ def interact_with_together_api(messages, model_link, diagnostic=False):
|
|
78 |
|
79 |
# Function to diagnose mental health issue
|
80 |
def diagnose_mental_health(messages):
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
# Create sidebar with model selection dropdown and reset button
|
84 |
selected_model = st.sidebar.selectbox("Select Model", list(model_pre_instructions.keys()))
|
|
|
78 |
|
79 |
# Function to diagnose mental health issue
|
80 |
def diagnose_mental_health(messages):
|
81 |
+
diagnostic_prompt = "Analyze the following conversation and predict the mental issue the user might be suffering from:"
|
82 |
+
diagnostic_messages = [{"role": "system", "content": "You are an AI model specialized in mental health diagnosis."},
|
83 |
+
{"role": "user", "content": diagnostic_prompt}]
|
84 |
+
for message in messages:
|
85 |
+
if message[0] == "user":
|
86 |
+
diagnostic_messages.append({"role": "user", "content": message[1]})
|
87 |
+
|
88 |
+
url = "https://api.together.xyz/v1/chat/completions"
|
89 |
+
payload = {
|
90 |
+
"model": model_link,
|
91 |
+
"temperature": 0.7,
|
92 |
+
"top_p": 0.9,
|
93 |
+
"top_k": 50,
|
94 |
+
"repetition_penalty": 1.2,
|
95 |
+
"n": 1,
|
96 |
+
"messages": diagnostic_messages,
|
97 |
+
}
|
98 |
+
|
99 |
+
TOGETHER_API_KEY = os.getenv('TOGETHER_API_KEY')
|
100 |
+
headers = {
|
101 |
+
"accept": "application/json",
|
102 |
+
"content-type": "application/json",
|
103 |
+
"Authorization": f"Bearer {TOGETHER_API_KEY}",
|
104 |
+
}
|
105 |
+
|
106 |
+
try:
|
107 |
+
response = requests.post(url, json=payload, headers=headers)
|
108 |
+
response.raise_for_status() # Ensure HTTP request was successful
|
109 |
+
response_data = response.json()
|
110 |
+
diagnosis = response_data["choices"][0]["message"]["content"]
|
111 |
+
except requests.exceptions.RequestException as e:
|
112 |
+
diagnosis = "Sorry, I couldn't perform the diagnosis. Please try again later."
|
113 |
+
|
114 |
+
return diagnosis
|
115 |
|
116 |
# Create sidebar with model selection dropdown and reset button
|
117 |
selected_model = st.sidebar.selectbox("Select Model", list(model_pre_instructions.keys()))
|