Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files
app.py
CHANGED
|
@@ -116,38 +116,6 @@ harmful_response = (
|
|
| 116 |
|
| 117 |
# Emotions dictionary removed - ChatGPT now handles all responses naturally
|
| 118 |
|
| 119 |
-
# Functions
|
| 120 |
-
def set_personal_info(name, age, gender, language, Guardian_info):
|
| 121 |
-
user_info.update({"name": name, "age": age, "gender": gender, "language": language, "Guardian_info": Guardian_info,})
|
| 122 |
-
return gr.update(visible=True), f"✅ Welcome {name}! Preferences saved."
|
| 123 |
-
|
| 124 |
-
def show_personal_data():
|
| 125 |
-
today = datetime.date.today().strftime("%Y-%m-%d (%A)")
|
| 126 |
-
return f"📅 {today}\n👤 Name: {user_info['name']}\n🎂 Age: {user_info['age']}\n♀ Gender: {user_info['gender']}\n🌐 Language: {user_info['language']}\n Guardian_info: {user_info['Guardian_info']}"
|
| 127 |
-
|
| 128 |
-
def generate_reply(input_text):
|
| 129 |
-
text = input_text.lower()
|
| 130 |
-
# Check for harmful keywords with word boundaries - crisis intervention
|
| 131 |
-
for word in harmful_keywords:
|
| 132 |
-
pattern = r'\b' + re.escape(word) + r'\b'
|
| 133 |
-
if re.search(pattern, text):
|
| 134 |
-
return harmful_response
|
| 135 |
-
|
| 136 |
-
# Use OpenAI ChatGPT for natural conversation
|
| 137 |
-
try:
|
| 138 |
-
response = client.chat.completions.create(
|
| 139 |
-
model="gpt-3.5-turbo", # or "gpt-4" for better responses
|
| 140 |
-
messages=[
|
| 141 |
-
{"role": "system", "content": SYSTEM_PROMPT},
|
| 142 |
-
{"role": "user", "content": input_text}
|
| 143 |
-
],
|
| 144 |
-
temperature=0.7,
|
| 145 |
-
max_tokens=200
|
| 146 |
-
)
|
| 147 |
-
return response.choices[0].message.content
|
| 148 |
-
except Exception as e:
|
| 149 |
-
return f"I'm having trouble connecting right now, but I'm here to listen. Can you tell me more about what you're feeling?"
|
| 150 |
-
|
| 151 |
# Functions
|
| 152 |
def set_personal_info(name, age, gender, language, Guardian_info):
|
| 153 |
user_info.update({"name": name, "age": age, "gender": gender, "language": language, "Guardian_info": Guardian_info,})
|
|
|
|
| 116 |
|
| 117 |
# Emotions dictionary removed - ChatGPT now handles all responses naturally
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
# Functions
|
| 120 |
def set_personal_info(name, age, gender, language, Guardian_info):
|
| 121 |
user_info.update({"name": name, "age": age, "gender": gender, "language": language, "Guardian_info": Guardian_info,})
|