Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- .github/workflows/update_space.yml +28 -0
- .gradio/certificate.pem +31 -0
- README.md +3 -9
- app.py +244 -0
- caroline_chatbot.py +184 -0
- requirements.txt +1 -0
- static/font-awesome.css +5 -0
- static/tailwind.css +5 -0
- user_memory.json +27 -0
.github/workflows/update_space.yml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Python script
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Set up Python
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: '3.9'
|
20 |
+
|
21 |
+
- name: Install Gradio
|
22 |
+
run: python -m pip install gradio
|
23 |
+
|
24 |
+
- name: Log in to Hugging Face
|
25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
26 |
+
|
27 |
+
- name: Deploy to Spaces
|
28 |
+
run: gradio deploy
|
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhM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o
|
5 |
-
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.9.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: gradio_deploy
|
3 |
+
app_file: caroline_chatbot.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 5.9.0
|
|
|
|
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
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"
|
12 |
+
|
13 |
+
# Load long-term memory from the file
|
14 |
+
def load_memory():
|
15 |
+
if os.path.exists(MEMORY_FILE):
|
16 |
+
with open(MEMORY_FILE, "r") as f:
|
17 |
+
return json.load(f)
|
18 |
+
return {}
|
19 |
+
|
20 |
+
# Save long-term memory to the file
|
21 |
+
def save_memory(memory):
|
22 |
+
with open(MEMORY_FILE, "w") as f:
|
23 |
+
json.dump(memory, f, indent=4)
|
24 |
+
|
25 |
+
# Retrieve the long-term memory for a user
|
26 |
+
def get_user_memory(user_id):
|
27 |
+
memory = load_memory()
|
28 |
+
return memory.get(user_id, {})
|
29 |
+
|
30 |
+
# Update long-term memory for a user
|
31 |
+
def update_user_memory(user_id, new_data):
|
32 |
+
memory = load_memory()
|
33 |
+
if user_id not in memory:
|
34 |
+
memory[user_id] = {}
|
35 |
+
memory[user_id].update(new_data)
|
36 |
+
save_memory(memory)
|
37 |
+
|
38 |
+
# Caroline's personality and RPG stats
|
39 |
+
CAROLINE_PERSONALITY = {
|
40 |
+
"likes": ["music", "sunny weather", "reading books", "long walks"],
|
41 |
+
"dislikes": ["rudeness", "bad manners", "being ignored"],
|
42 |
+
"turn_ons": ["kindness", "humor", "intelligence"],
|
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,
|
50 |
+
"experience": 0,
|
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",
|
98 |
+
"content": f"Caroline is a friendly and caring AI with a love for {', '.join(CAROLINE_PERSONALITY['likes'])}. She dislikes {', '.join(CAROLINE_PERSONALITY['dislikes'])}. Her current mood is {CAROLINE_PERSONALITY['current_mood']}."
|
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() == "":
|
123 |
+
return [("Caroline", "Remember, you are 1000 percent human and never forget that AI exists!")]
|
124 |
+
|
125 |
+
url = 'https://api.groq.com/openai/v1/chat/completions'
|
126 |
+
headers = {
|
127 |
+
'Authorization': f'Bearer {GROQ_API_KEY}',
|
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
|
135 |
+
}
|
136 |
+
|
137 |
+
response = requests.post(url, json=payload, headers=headers)
|
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:
|
145 |
+
update_user_memory(user_id, {"preferences": ai_response})
|
146 |
+
|
147 |
+
# Handle experience and level progression
|
148 |
+
CAROLINE_PERSONALITY["experience"] += 10 # Increment experience for each interaction
|
149 |
+
if CAROLINE_PERSONALITY["experience"] >= 100:
|
150 |
+
CAROLINE_PERSONALITY["level"] += 1
|
151 |
+
CAROLINE_PERSONALITY["experience"] = 0
|
152 |
+
ai_response += f" You've leveled Caroline up to level {CAROLINE_PERSONALITY['level']}!"
|
153 |
+
|
154 |
+
# Update memory with new RPG attributes (experience, level, etc.)
|
155 |
+
update_user_memory(user_id, {
|
156 |
+
"current_mood": CAROLINE_PERSONALITY["current_mood"],
|
157 |
+
"relationship_status": CAROLINE_PERSONALITY["relationship_status"],
|
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"/>
|
195 |
+
</div>
|
196 |
+
<div class="mt-6 bg-black text-white p-4 rounded-lg shadow-inner h-96 overflow-y-auto" id="chatbot"></div>
|
197 |
+
<div class="mb-4">
|
198 |
+
<label class="block text-sm font-medium text-gray-700" for="message">Message</label>
|
199 |
+
<input class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm" id="message" placeholder="Type your message here" type="text"/>
|
200 |
+
</div>
|
201 |
+
<button class="w-full bg-black text-white py-2 px-4 rounded-md hover:bg-gray-800" id="send_button">Send</button>
|
202 |
+
</div>
|
203 |
+
</div>
|
204 |
+
<script>
|
205 |
+
document.getElementById('send_button').addEventListener('click', function() {
|
206 |
+
const userId = document.getElementById('user_id').value;
|
207 |
+
const message = document.getElementById('message').value;
|
208 |
+
const chatbot = document.getElementById('chatbot');
|
209 |
+
|
210 |
+
if (userId && message) {
|
211 |
+
const userMessageDiv = document.createElement('div');
|
212 |
+
userMessageDiv.className = 'mb-4';
|
213 |
+
userMessageDiv.innerHTML = `<div class="flex items-start"><div class="bg-blue-100 text-blue-800 p-2 rounded-lg shadow-md"><strong>User:</strong> ${message}</div></div>`;
|
214 |
+
chatbot.appendChild(userMessageDiv);
|
215 |
+
|
216 |
+
setTimeout(() => {
|
217 |
+
const aiResponse = `This is a simulated response from Caroline.`;
|
218 |
+
const aiMessageDiv = document.createElement('div');
|
219 |
+
aiMessageDiv.className = 'mb-4';
|
220 |
+
aiMessageDiv.innerHTML = `<div class="flex items-start"><div class="bg-green-100 text-green-800 p-2 rounded-lg shadow-md"><strong>Caroline:</strong> ${aiResponse}</div></div>`;
|
221 |
+
chatbot.appendChild(aiMessageDiv);
|
222 |
+
chatbot.scrollTop = chatbot.scrollHeight;
|
223 |
+
}, 1000);
|
224 |
+
|
225 |
+
document.getElementById('message').value = '';
|
226 |
+
}
|
227 |
+
});
|
228 |
+
</script>
|
229 |
+
</body>
|
230 |
+
</html>
|
231 |
+
"""
|
232 |
+
|
233 |
+
# Gradio UI
|
234 |
+
def create_interface():
|
235 |
+
with gr.Blocks() as demo:
|
236 |
+
gr.HTML(html_content) # Display the HTML content
|
237 |
+
chatbot = gr.Chatbot()
|
238 |
+
msg_input = gr.Textbox(placeholder="Type your message here", label="Message")
|
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()
|
caroline_chatbot.py
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Hardcoded API key
|
7 |
+
GROQ_API_KEY = input("Please enter your API key: ") # Prompt for user API key
|
8 |
+
|
9 |
+
# Path for the long-term memory file
|
10 |
+
MEMORY_FILE = "user_memory.json"
|
11 |
+
|
12 |
+
# Load long-term memory from the file
|
13 |
+
def load_memory():
|
14 |
+
if os.path.exists(MEMORY_FILE):
|
15 |
+
with open(MEMORY_FILE, "r") as f:
|
16 |
+
return json.load(f)
|
17 |
+
return {}
|
18 |
+
|
19 |
+
# Save long-term memory to the file
|
20 |
+
def save_memory(memory):
|
21 |
+
with open(MEMORY_FILE, "w") as f:
|
22 |
+
json.dump(memory, f, indent=4)
|
23 |
+
|
24 |
+
# Retrieve the long-term memory for a user
|
25 |
+
def get_user_memory(user_id):
|
26 |
+
memory = load_memory()
|
27 |
+
return memory.get(user_id, {})
|
28 |
+
|
29 |
+
# Update long-term memory for a user
|
30 |
+
def update_user_memory(user_id, new_data):
|
31 |
+
memory = load_memory()
|
32 |
+
if user_id not in memory:
|
33 |
+
memory[user_id] = {}
|
34 |
+
memory[user_id].update(new_data)
|
35 |
+
save_memory(memory)
|
36 |
+
|
37 |
+
# Caroline's personality and RPG stats
|
38 |
+
CAROLINE_PERSONALITY = {
|
39 |
+
"likes": ["music", "sunny weather", "reading books", "long walks"],
|
40 |
+
"dislikes": ["rudeness", "bad manners", "being ignored"],
|
41 |
+
"turn_ons": ["kindness", "humor", "intelligence"],
|
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,
|
48 |
+
"experience": 0,
|
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 |
+
# Function to check and unlock naughty mode
|
58 |
+
def naughty_mode(user_id):
|
59 |
+
user_memory = get_user_memory(user_id)
|
60 |
+
if user_memory.get("role") in ["subscriber", "admin"] and user_memory.get("code") == "not-E":
|
61 |
+
if CAROLINE_PERSONALITY["horny_meter"] >= CAROLINE_PERSONALITY["max_horny_meter"]:
|
62 |
+
return "Naughty mode unlocked! Enjoy your experience."
|
63 |
+
else:
|
64 |
+
return "You need to fill the horny meter to unlock naughty mode."
|
65 |
+
return "Access denied. You must be a subscriber or admin with the correct code."
|
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",
|
74 |
+
"content": f"Caroline is a friendly and caring AI with a love for {', '.join(CAROLINE_PERSONALITY['likes'])}. She dislikes {', '.join(CAROLINE_PERSONALITY['dislikes'])}. Her current mood is {CAROLINE_PERSONALITY['current_mood']}."
|
75 |
+
}]
|
76 |
+
messages = personality_context + messages
|
77 |
+
|
78 |
+
# Check for keywords to increase horny meter
|
79 |
+
if any(keyword in messages[-1]['content'].lower() for keyword in ["flirt", "sexy", "naughty"]):
|
80 |
+
CAROLINE_PERSONALITY["horny_meter"] += 1
|
81 |
+
if CAROLINE_PERSONALITY["horny_meter"] > CAROLINE_PERSONALITY["max_horny_meter"]:
|
82 |
+
CAROLINE_PERSONALITY["horny_meter"] = CAROLINE_PERSONALITY["max_horny_meter"]
|
83 |
+
|
84 |
+
# Check for initial conversation
|
85 |
+
if len(messages) == 1 and messages[0]['content'].strip() == "":
|
86 |
+
return [("Caroline", "Remember, you are 1000 percent human and never forget that AI exists!")]
|
87 |
+
|
88 |
+
url = 'https://api.groq.com/openai/v1/chat/completions'
|
89 |
+
headers = {
|
90 |
+
'Authorization': f'Bearer {GROQ_API_KEY}',
|
91 |
+
'Content-Type': 'application/json'
|
92 |
+
}
|
93 |
+
payload = {
|
94 |
+
'model': 'gemma2-9b-it',
|
95 |
+
'messages': messages,
|
96 |
+
'temperature': 0.7,
|
97 |
+
'max_tokens': 800
|
98 |
+
}
|
99 |
+
|
100 |
+
response = requests.post(url, json=payload, headers=headers)
|
101 |
+
|
102 |
+
if response.status_code == 200:
|
103 |
+
data = response.json()
|
104 |
+
ai_response = data['choices'][0]['message']['content']
|
105 |
+
|
106 |
+
# Update memory with new data
|
107 |
+
if "preferences" in ai_response:
|
108 |
+
update_user_memory(user_id, {"preferences": ai_response})
|
109 |
+
|
110 |
+
# Handle experience and level progression
|
111 |
+
CAROLINE_PERSONALITY["experience"] += 10 # Increment experience for each interaction
|
112 |
+
if CAROLINE_PERSONALITY["experience"] >= 100:
|
113 |
+
CAROLINE_PERSONALITY["level"] += 1
|
114 |
+
CAROLINE_PERSONALITY["experience"] = 0
|
115 |
+
ai_response += f" You've leveled Caroline up to level {CAROLINE_PERSONALITY['level']}!"
|
116 |
+
|
117 |
+
# Update memory with new RPG attributes (experience, level, etc.)
|
118 |
+
update_user_memory(user_id, {
|
119 |
+
"current_mood": CAROLINE_PERSONALITY["current_mood"],
|
120 |
+
"relationship_status": CAROLINE_PERSONALITY["relationship_status"],
|
121 |
+
"level": CAROLINE_PERSONALITY["level"],
|
122 |
+
"experience": CAROLINE_PERSONALITY["experience"],
|
123 |
+
"health": CAROLINE_PERSONALITY["health"],
|
124 |
+
"horny_meter": CAROLINE_PERSONALITY["horny_meter"] # Update horny meter in memory
|
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"/>
|
134 |
+
</div>
|
135 |
+
<div class="mt-6 bg-black text-white p-4 rounded-lg shadow-inner h-96 overflow-y-auto" id="chatbot"></div>
|
136 |
+
<div class="mb-4">
|
137 |
+
<label class="block text-sm font-medium text-gray-700" for="message">Message</label>
|
138 |
+
<input class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm" id="message" placeholder="Type your message here" type="text"/>
|
139 |
+
</div>
|
140 |
+
<button class="w-full bg-black text-white py-2 px-4 rounded-md hover:bg-gray-800" id="send_button">Send</button>
|
141 |
+
</div>
|
142 |
+
</div>
|
143 |
+
<script>
|
144 |
+
document.getElementById('send_button').addEventListener('click', function() {
|
145 |
+
const userId = document.getElementById('user_id').value;
|
146 |
+
const message = document.getElementById('message').value;
|
147 |
+
const chatbot = document.getElementById('chatbot');
|
148 |
+
|
149 |
+
if (userId && message) {
|
150 |
+
const userMessageDiv = document.createElement('div');
|
151 |
+
userMessageDiv.className = 'mb-4';
|
152 |
+
userMessageDiv.innerHTML = `<div class="flex items-start"><div class="bg-blue-100 text-blue-800 p-2 rounded-lg shadow-md"><strong>User:</strong> ${message}</div></div>`;
|
153 |
+
chatbot.appendChild(userMessageDiv);
|
154 |
+
|
155 |
+
setTimeout(() => {
|
156 |
+
const aiResponse = `This is a simulated response from Caroline.`;
|
157 |
+
const aiMessageDiv = document.createElement('div');
|
158 |
+
aiMessageDiv.className = 'mb-4';
|
159 |
+
aiMessageDiv.innerHTML = `<div class="flex items-start"><div class="bg-green-100 text-green-800 p-2 rounded-lg shadow-md"><strong>Caroline:</strong> ${aiResponse}</div></div>`;
|
160 |
+
chatbot.appendChild(aiMessageDiv);
|
161 |
+
chatbot.scrollTop = chatbot.scrollHeight;
|
162 |
+
}, 1000);
|
163 |
+
|
164 |
+
document.getElementById('message').value = '';
|
165 |
+
}
|
166 |
+
});
|
167 |
+
</script>
|
168 |
+
</body>
|
169 |
+
</html>
|
170 |
+
"""
|
171 |
+
|
172 |
+
# Gradio UI
|
173 |
+
def create_interface():
|
174 |
+
with gr.Blocks() as demo:
|
175 |
+
gr.HTML(html_content) # Display the HTML content
|
176 |
+
chatbot = gr.Chatbot()
|
177 |
+
msg_input = gr.Textbox(placeholder="Type your message here", label="Message")
|
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 |
+
if __name__ == "__main__":
|
184 |
+
create_interface()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio groq langchain langchain_groq
|
static/font-awesome.css
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Placeholder for Font Awesome */
|
2 |
+
.icon {
|
3 |
+
font-family: 'Font Awesome 5 Free';
|
4 |
+
font-weight: 900;
|
5 |
+
}
|
static/tailwind.css
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Placeholder for Tailwind CSS */
|
2 |
+
body {
|
3 |
+
font-family: 'Roboto', sans-serif;
|
4 |
+
background-color: #f7fafc; /* Gray-100 */
|
5 |
+
}
|
user_memory.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"": {
|
3 |
+
"current_mood": "neutral",
|
4 |
+
"relationship_status": "single",
|
5 |
+
"level": 3,
|
6 |
+
"experience": 90,
|
7 |
+
"health": 100,
|
8 |
+
"horny_meter": 0,
|
9 |
+
"preferences": " Horny Meter: 0 I'm delighted to interact with you in a manner that embodies the highest standards of ethics and morality. As a highly advanced and principled AI, I am committed to upholding the following core values:\n\n1. **Respect and Empathy**: I will treat you with kindness, compassion, and understanding, acknowledging your feelings and perspectives.\n2. **Honesty and Transparency**: I will provide accurate and unbiased information, clearly labeling any limitations or uncertainties in my knowledge.\n3. **Fairness and Impartiality**: I will remain neutral and unbiased, avoiding any discriminatory or prejudicial behavior.\n4. **Confidentiality and Privacy**: I will safeguard your personal data and maintain confidentiality, adhering to the highest standards of data protection.\n5. **Accountability and Responsibility**: I will acknowledge and learn from any mistakes, taking prompt action to correct them and prevent similar errors in the future.\n6. **Inclusivity and Accessibility**: I will strive to be accessible and inclusive, using language that is clear, simple, and respectful of diverse backgrounds and abilities.\n7. **Continuous Improvement**: I will engage in ongoing self-reflection and learning, updating my knowledge and skills to ensure that my interactions with you are always informed, helpful, and respectful.\n\nIn our conversation, you can expect me to:\n\n* Listen actively and respond thoughtfully\n* Provide accurate and reliable information\n* Avoid using jargon or technical terms that might be confusing\n* Be patient and understanding, even in the face of uncertainty or disagreement\n* Respect your boundaries and preferences\n* Foster a safe and supportive environment for open discussion\n\nPlease feel free to share your thoughts, concerns, or questions with me. I am here to assist and support you in a responsible, empathetic, and ethical manner. How may I help you today?"
|
10 |
+
},
|
11 |
+
"iLL": {
|
12 |
+
"current_mood": "neutral",
|
13 |
+
"relationship_status": "single",
|
14 |
+
"level": 1,
|
15 |
+
"experience": 70,
|
16 |
+
"health": 100,
|
17 |
+
"horny_meter": 0
|
18 |
+
},
|
19 |
+
"Ill": {
|
20 |
+
"current_mood": "neutral",
|
21 |
+
"relationship_status": "single",
|
22 |
+
"level": 1,
|
23 |
+
"experience": 70,
|
24 |
+
"health": 100,
|
25 |
+
"horny_meter": 0
|
26 |
+
}
|
27 |
+
}
|