Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,28 @@ def generate_empathetic_response(user_input, retrieved_question):
|
|
72 |
return response.choices[0].message.content
|
73 |
except Exception as e:
|
74 |
return "I'm sorry, I couldn't process your request."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
# β
Streamlit UI Setup
|
77 |
st.title("π§ MindSpark AI Psychiatric Assistant")
|
@@ -97,3 +119,21 @@ if st.button("Summarize Chat"):
|
|
97 |
summary = summarization_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
98 |
st.subheader("Chat Summary")
|
99 |
st.write(summary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
return response.choices[0].message.content
|
73 |
except Exception as e:
|
74 |
return "I'm sorry, I couldn't process your request."
|
75 |
+
# β
Function to detect disorders
|
76 |
+
def detect_disorders(chat_history):
|
77 |
+
"""Detect psychiatric disorders from full chat history."""
|
78 |
+
full_chat_text = " ".join(chat_history)
|
79 |
+
text_embedding = similarity_model.encode([full_chat_text], convert_to_numpy=True)
|
80 |
+
distances, indices = index.search(text_embedding, 3)
|
81 |
+
|
82 |
+
if indices[0][0] == -1:
|
83 |
+
return ["No matching disorder found."]
|
84 |
+
|
85 |
+
disorders = [recommendations_df["Disorder"].iloc[i] for i in indices[0]]
|
86 |
+
return disorders
|
87 |
+
|
88 |
+
# β
Function to get treatment recommendations
|
89 |
+
def get_treatment(detected_disorders):
|
90 |
+
"""Retrieve treatment recommendations based on detected disorders."""
|
91 |
+
treatments = {
|
92 |
+
disorder: recommendations_df[recommendations_df["Disorder"] == disorder]["Treatment Recommendation"].values[0]
|
93 |
+
for disorder in detected_disorders if disorder in recommendations_df["Disorder"].values
|
94 |
+
}
|
95 |
+
return treatments
|
96 |
+
|
97 |
|
98 |
# β
Streamlit UI Setup
|
99 |
st.title("π§ MindSpark AI Psychiatric Assistant")
|
|
|
119 |
summary = summarization_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
120 |
st.subheader("Chat Summary")
|
121 |
st.write(summary)
|
122 |
+
if st.button("Detect Disorders"):
|
123 |
+
if chat_history.strip():
|
124 |
+
disorders = detect_disorders(chat_history.split("\n"))
|
125 |
+
st.write("**Detected Disorders:**")
|
126 |
+
for disorder in disorders:
|
127 |
+
st.write(f"- {disorder}")
|
128 |
+
else:
|
129 |
+
st.error("β Please enter chat history.")
|
130 |
+
|
131 |
+
if st.button("Get Treatment Recommendations"):
|
132 |
+
if chat_history.strip():
|
133 |
+
detected_disorders = detect_disorders(chat_history.split("\n"))
|
134 |
+
treatments = get_treatment(detected_disorders)
|
135 |
+
st.write("**Treatment Recommendations:**")
|
136 |
+
for disorder, treatment in treatments.items():
|
137 |
+
st.write(f"**{disorder}:** {treatment}")
|
138 |
+
else:
|
139 |
+
st.error("β Please enter chat history.")
|