treasuremars commited on
Commit
f765bd6
·
verified ·
1 Parent(s): 1227e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -29
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
- if not is_relevant_query(prompt):
92
- response = "I'm sorry, but your question seems to be out of my scope. Please ask about drugs, side effects, or related medical conditions."
93
- else:
94
- # Craft System Prompt based on sentiment
95
- system_prompt = SYSTEM_PROMPT_GENERAL
96
- if user_sentiment < 0: # User expresses negative sentiment
97
- system_prompt = f"""{system_prompt}
98
- The user seems to be feeling down. Prioritize empathetic responses and open-ended questions."""
99
-
100
- # Format prompt using LangChain's PromptTemplate
101
- formatted_prompt = prompt_template.format(
102
- system_prompt=system_prompt,
103
- user_input=prompt
104
- )
105
-
106
- # Generate a response using Hugging Face API
107
- response = ""
108
- for message in client.chat_completion(
109
- messages=[{"role": "user", "content": formatted_prompt}],
110
- max_tokens=500,
111
- stream=True,
112
- ):
113
- response += message.choices[0].delta.content
114
-
115
- # Process response for specific tokens
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()})