Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- caroline_chatbot.py +84 -24
caroline_chatbot.py
CHANGED
|
@@ -2,9 +2,10 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# Hardcoded API key
|
| 7 |
-
GROQ_API_KEY =
|
| 8 |
|
| 9 |
# Path for the long-term memory file
|
| 10 |
MEMORY_FILE = "user_memory.json"
|
|
@@ -42,6 +43,7 @@ CAROLINE_PERSONALITY = {
|
|
| 42 |
"turn_offs": ["dishonesty", "negativity", "arrogance"],
|
| 43 |
"bio": "Hi, I'm Caroline! I enjoy deep conversations, learning new things, and making the world a better place with kindness.",
|
| 44 |
"greeting": "Hey there, love! How’s your day going?",
|
|
|
|
| 45 |
"current_mood": "neutral", # moods: neutral, happy, upset, angry, distant
|
| 46 |
"relationship_status": "single", # single or in a relationship
|
| 47 |
"level": 1,
|
|
@@ -49,25 +51,47 @@ CAROLINE_PERSONALITY = {
|
|
| 49 |
"health": 100,
|
| 50 |
"quests": [],
|
| 51 |
"items": [],
|
| 52 |
-
"preferences": {}
|
| 53 |
-
"horny_meter": 0, # Initialize horny meter
|
| 54 |
-
"max_horny_meter": 10 # Maximum value for horny meter
|
| 55 |
}
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Chat with AI using Caroline's personality and RPG system
|
| 68 |
def chat_with_ai(messages, user_id):
|
|
|
|
| 69 |
user_memory = get_user_memory(user_id)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
# Adding Caroline's personality to the memory context
|
| 72 |
personality_context = [{
|
| 73 |
"role": "system",
|
|
@@ -75,11 +99,24 @@ def chat_with_ai(messages, user_id):
|
|
| 75 |
}]
|
| 76 |
messages = personality_context + messages
|
| 77 |
|
| 78 |
-
# Check for
|
| 79 |
-
if any(keyword in messages[
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Check for initial conversation
|
| 85 |
if len(messages) == 1 and messages[0]['content'].strip() == "":
|
|
@@ -91,7 +128,7 @@ def chat_with_ai(messages, user_id):
|
|
| 91 |
'Content-Type': 'application/json'
|
| 92 |
}
|
| 93 |
payload = {
|
| 94 |
-
'model': '
|
| 95 |
'messages': messages,
|
| 96 |
'temperature': 0.7,
|
| 97 |
'max_tokens': 800
|
|
@@ -101,7 +138,7 @@ def chat_with_ai(messages, user_id):
|
|
| 101 |
|
| 102 |
if response.status_code == 200:
|
| 103 |
data = response.json()
|
| 104 |
-
ai_response
|
| 105 |
|
| 106 |
# Update memory with new data
|
| 107 |
if "preferences" in ai_response:
|
|
@@ -121,13 +158,37 @@ def chat_with_ai(messages, user_id):
|
|
| 121 |
"level": CAROLINE_PERSONALITY["level"],
|
| 122 |
"experience": CAROLINE_PERSONALITY["experience"],
|
| 123 |
"health": CAROLINE_PERSONALITY["health"],
|
| 124 |
-
"horny_meter": CAROLINE_PERSONALITY["horny_meter"]
|
| 125 |
})
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
<div class="flex items-center mb-4">
|
| 128 |
<img alt="Caroline Image" class="w-24 h-24 rounded-full mr-4" src="https://storage.googleapis.com/a1aa/image/Wv7CfnTUzH3FKqR5cJdS9f5i8u1atlbJfaHQNdkGJFKDKvrnA.jpg"/>
|
| 129 |
<p>Hi, I'm Caroline! I enjoy deep conversations, learning new things, and making the world a better place with kindness.</p>
|
| 130 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
<div class="mb-4">
|
| 132 |
<label class="block text-sm font-medium text-gray-700" for="user_id">User ID</label>
|
| 133 |
<input class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm" id="user_id" placeholder="Enter your user ID" type="text"/>
|
|
@@ -178,7 +239,6 @@ def create_interface():
|
|
| 178 |
send_button = gr.Button("Send")
|
| 179 |
user_id_input = gr.Textbox(placeholder="Enter your user ID", label="User ID")
|
| 180 |
send_button.click(chat_with_ai, inputs=[msg_input, user_id_input], outputs=chatbot)
|
| 181 |
-
demo.launch()
|
| 182 |
|
| 183 |
-
|
| 184 |
-
create_interface()
|
|
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
+
import random
|
| 6 |
|
| 7 |
# Hardcoded API key
|
| 8 |
+
GROQ_API_KEY = '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'
|
| 9 |
|
| 10 |
# Path for the long-term memory file
|
| 11 |
MEMORY_FILE = "user_memory.json"
|
|
|
|
| 43 |
"turn_offs": ["dishonesty", "negativity", "arrogance"],
|
| 44 |
"bio": "Hi, I'm Caroline! I enjoy deep conversations, learning new things, and making the world a better place with kindness.",
|
| 45 |
"greeting": "Hey there, love! How’s your day going?",
|
| 46 |
+
"horny_meter": 0, # Initialize horny meter
|
| 47 |
"current_mood": "neutral", # moods: neutral, happy, upset, angry, distant
|
| 48 |
"relationship_status": "single", # single or in a relationship
|
| 49 |
"level": 1,
|
|
|
|
| 51 |
"health": 100,
|
| 52 |
"quests": [],
|
| 53 |
"items": [],
|
| 54 |
+
"preferences": {}
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
+
# Initialize conversation memory
|
| 58 |
+
conversation_memory = []
|
| 59 |
+
# Temporary history storage
|
| 60 |
+
temporary_history = []
|
| 61 |
+
|
| 62 |
+
# Function to clear temporary history
|
| 63 |
+
def clear_temporary_history():
|
| 64 |
+
global temporary_history
|
| 65 |
+
temporary_history.clear()
|
| 66 |
+
|
| 67 |
+
# List of exercises to become a better boyfriend
|
| 68 |
+
EXERCISES = [
|
| 69 |
+
"Plan a surprise date for your partner.",
|
| 70 |
+
"Write a heartfelt letter expressing your feelings.",
|
| 71 |
+
"Practice active listening by summarizing what your partner says.",
|
| 72 |
+
"Learn about your partner's love language and try to speak it.",
|
| 73 |
+
"Spend quality time together without distractions (like phones)."
|
| 74 |
+
]
|
| 75 |
|
| 76 |
# Chat with AI using Caroline's personality and RPG system
|
| 77 |
def chat_with_ai(messages, user_id):
|
| 78 |
+
global conversation_memory
|
| 79 |
user_memory = get_user_memory(user_id)
|
| 80 |
|
| 81 |
+
# Suggest an exercise if the user asks for advice
|
| 82 |
+
if isinstance(messages, str):
|
| 83 |
+
messages = [{"role": "user", "content": messages}]
|
| 84 |
+
if any(keyword in messages[0]['content'].lower() for keyword in ["better boyfriend", "relationship advice", "improve"]):
|
| 85 |
+
exercise = random.choice(EXERCISES)
|
| 86 |
+
return [("Caroline", f"Here's an exercise to help you become a better boyfriend: {exercise}")]
|
| 87 |
+
|
| 88 |
+
# Append user message to conversation memory
|
| 89 |
+
conversation_memory.append(messages[0]) # Store the latest user message
|
| 90 |
+
|
| 91 |
+
# Clear temporary history if needed (for testing purposes)
|
| 92 |
+
if len(temporary_history) > 5: # Example condition to clear history
|
| 93 |
+
clear_temporary_history()
|
| 94 |
+
|
| 95 |
# Adding Caroline's personality to the memory context
|
| 96 |
personality_context = [{
|
| 97 |
"role": "system",
|
|
|
|
| 99 |
}]
|
| 100 |
messages = personality_context + messages
|
| 101 |
|
| 102 |
+
# Check for mood and horny meter adjustments
|
| 103 |
+
if any(keyword in messages[0]['content'].lower() for keyword in ["not interested", "no", "stop", "don't want to talk about sex"]):
|
| 104 |
+
ai_response = "" # Remove the introductory message
|
| 105 |
+
elif any(keyword in messages[0]['content'].lower() for keyword in ["horny", "sexy", "attractive"]):
|
| 106 |
+
CAROLINE_PERSONALITY["horny_meter"] += 1 # Increment horny meter
|
| 107 |
+
CAROLINE_PERSONALITY["current_mood"] = "happy" # Change mood to happy
|
| 108 |
+
ai_response = "Caroline's feeling a bit frisky! Her horny meter is now at " + str(CAROLINE_PERSONALITY["horny_meter"]) + "."
|
| 109 |
+
elif any(keyword in messages[0]['content'].lower() for keyword in ["sad", "upset", "angry"]):
|
| 110 |
+
CAROLINE_PERSONALITY["current_mood"] = "upset" # Change mood to upset
|
| 111 |
+
ai_response = "Caroline is feeling a bit down."
|
| 112 |
+
elif any(keyword in messages[0]['content'].lower() for keyword in ["dream", "sex dream", "intimate"]):
|
| 113 |
+
ai_response = "That sounds interesting! I'd love to hear more about your dream."
|
| 114 |
+
else:
|
| 115 |
+
ai_response = ""
|
| 116 |
+
|
| 117 |
+
# Display the horny meter value
|
| 118 |
+
horny_meter_display = f"Horny Meter: {CAROLINE_PERSONALITY['horny_meter']}"
|
| 119 |
+
ai_response += f" {horny_meter_display}"
|
| 120 |
|
| 121 |
# Check for initial conversation
|
| 122 |
if len(messages) == 1 and messages[0]['content'].strip() == "":
|
|
|
|
| 128 |
'Content-Type': 'application/json'
|
| 129 |
}
|
| 130 |
payload = {
|
| 131 |
+
'model': 'llama-3.3-70b-versatile',
|
| 132 |
'messages': messages,
|
| 133 |
'temperature': 0.7,
|
| 134 |
'max_tokens': 800
|
|
|
|
| 138 |
|
| 139 |
if response.status_code == 200:
|
| 140 |
data = response.json()
|
| 141 |
+
ai_response += " " + data['choices'][0]['message']['content']
|
| 142 |
|
| 143 |
# Update memory with new data
|
| 144 |
if "preferences" in ai_response:
|
|
|
|
| 158 |
"level": CAROLINE_PERSONALITY["level"],
|
| 159 |
"experience": CAROLINE_PERSONALITY["experience"],
|
| 160 |
"health": CAROLINE_PERSONALITY["health"],
|
| 161 |
+
"horny_meter": CAROLINE_PERSONALITY["horny_meter"]
|
| 162 |
})
|
| 163 |
|
| 164 |
+
# Return the response in the correct format
|
| 165 |
+
return [("Caroline", ai_response)]
|
| 166 |
+
else:
|
| 167 |
+
return f"Error: {response.status_code}, {response.text}"
|
| 168 |
+
|
| 169 |
+
# HTML content for the frontend
|
| 170 |
+
html_content = """
|
| 171 |
+
<html lang="en">
|
| 172 |
+
<head>
|
| 173 |
+
<meta charset="utf-8"/>
|
| 174 |
+
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
|
| 175 |
+
<title>AI Girlfriend Chat - Caroline</title>
|
| 176 |
+
<link href="static/tailwind.css" rel="stylesheet"/>
|
| 177 |
+
<link href="static/font-awesome.css" rel="stylesheet"/>
|
| 178 |
+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"/>
|
| 179 |
+
</head>
|
| 180 |
+
<body class="bg-gray-100 font-roboto">
|
| 181 |
+
<div class="container mx-auto p-4">
|
| 182 |
+
<div class="bg-white shadow-md rounded-lg p-6">
|
| 183 |
+
<h1 class="text-2xl font-bold mb-4">AI Girlfriend Chat - Caroline</h1>
|
| 184 |
<div class="flex items-center mb-4">
|
| 185 |
<img alt="Caroline Image" class="w-24 h-24 rounded-full mr-4" src="https://storage.googleapis.com/a1aa/image/Wv7CfnTUzH3FKqR5cJdS9f5i8u1atlbJfaHQNdkGJFKDKvrnA.jpg"/>
|
| 186 |
<p>Hi, I'm Caroline! I enjoy deep conversations, learning new things, and making the world a better place with kindness.</p>
|
| 187 |
</div>
|
| 188 |
+
<div class="mb-4" id="horny_meter_display">
|
| 189 |
+
<label class="block text-sm font-medium text-gray-700" for="horny_meter">Horny Meter</label>
|
| 190 |
+
<input class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm" id="horny_meter" value="0" readonly/>
|
| 191 |
+
</div>
|
| 192 |
<div class="mb-4">
|
| 193 |
<label class="block text-sm font-medium text-gray-700" for="user_id">User ID</label>
|
| 194 |
<input class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm" id="user_id" placeholder="Enter your user ID" type="text"/>
|
|
|
|
| 239 |
send_button = gr.Button("Send")
|
| 240 |
user_id_input = gr.Textbox(placeholder="Enter your user ID", label="User ID")
|
| 241 |
send_button.click(chat_with_ai, inputs=[msg_input, user_id_input], outputs=chatbot)
|
| 242 |
+
demo.launch(share=True, debug=True) # Enable sharing and debugging
|
| 243 |
|
| 244 |
+
create_interface()
|
|
|