Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -88,35 +88,31 @@ if prompt := st.chat_input():
|
|
88 |
user_sentiment = TextBlob(prompt).sentiment.polarity
|
89 |
|
90 |
# Check if the query is relevant to the drug-side effects dataset
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
if "Ashley:" in response:
|
117 |
-
response = response.split("Treasure:")[1].strip()
|
118 |
-
elif "User:" in response:
|
119 |
-
response = response.split("Assistant:")[1].strip()
|
120 |
|
121 |
# Append assistant message to the session state
|
122 |
st.session_state.messages.append({"role": "assistant", "content": response.strip()})
|
|
|
88 |
user_sentiment = TextBlob(prompt).sentiment.polarity
|
89 |
|
90 |
# Check if the query is relevant to the drug-side effects dataset
|
91 |
+
system_prompt = SYSTEM_PROMPT_GENERAL
|
92 |
+
if user_sentiment < 0: # User expresses negative sentiment
|
93 |
+
system_prompt = f"""{system_prompt}
|
94 |
+
The user seems to be feeling down. Prioritize empathetic responses and open-ended questions."""
|
95 |
+
|
96 |
+
# Format prompt using LangChain's PromptTemplate
|
97 |
+
formatted_prompt = prompt_template.format(
|
98 |
+
system_prompt=system_prompt,
|
99 |
+
user_input=prompt
|
100 |
+
)
|
101 |
+
|
102 |
+
# Generate a response using Hugging Face API
|
103 |
+
response = ""
|
104 |
+
for message in client.chat_completion(
|
105 |
+
messages=[{"role": "user", "content": formatted_prompt}],
|
106 |
+
max_tokens=500,
|
107 |
+
stream=True,
|
108 |
+
):
|
109 |
+
response += message.choices[0].delta.content
|
110 |
+
|
111 |
+
# Process response for specific tokens
|
112 |
+
if "Ashley:" in response:
|
113 |
+
response = response.split("Treasure:")[1].strip()
|
114 |
+
elif "User:" in response:
|
115 |
+
response = response.split("Assistant:")[1].strip()
|
|
|
|
|
|
|
|
|
116 |
|
117 |
# Append assistant message to the session state
|
118 |
st.session_state.messages.append({"role": "assistant", "content": response.strip()})
|