Capx
/

Alyosha11 commited on
Commit
7b449d7
1 Parent(s): 4b70306

Upload 2 files

Browse files
Files changed (2) hide show
  1. capx.html +175 -0
  2. capybara_dating_app_api.py +156 -0
capx.html ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Capybara Dating App - Personality Quiz</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
8
+ <style>
9
+ body {
10
+ font-family: 'Poppins', sans-serif;
11
+ max-width: 800px;
12
+ margin: 0 auto;
13
+ padding: 20px;
14
+ background-color: #f0e6d2;
15
+ color: #5a3921;
16
+ line-height: 1.6;
17
+ }
18
+ .container {
19
+ background-color: #fff;
20
+ border-radius: 15px;
21
+ padding: 30px;
22
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
23
+ }
24
+ h1 {
25
+ color: #ff6b35;
26
+ text-align: center;
27
+ font-size: 2.5em;
28
+ margin-bottom: 20px;
29
+ }
30
+ #question, #result {
31
+ font-size: 1.2em;
32
+ margin-bottom: 20px;
33
+ background-color: #fffaf0;
34
+ padding: 20px;
35
+ border-radius: 8px;
36
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
37
+ }
38
+ #answer {
39
+ width: 100%;
40
+ padding: 15px;
41
+ margin-bottom: 20px;
42
+ border: 2px solid #ff6b35;
43
+ border-radius: 8px;
44
+ font-size: 1em;
45
+ transition: border-color 0.3s ease;
46
+ }
47
+ #answer:focus {
48
+ outline: none;
49
+ border-color: #ff4500;
50
+ }
51
+ button {
52
+ padding: 12px 24px;
53
+ font-size: 1em;
54
+ background-color: #ff6b35;
55
+ color: white;
56
+ border: none;
57
+ border-radius: 25px;
58
+ cursor: pointer;
59
+ transition: background-color 0.3s ease, transform 0.1s ease;
60
+ }
61
+ button:hover {
62
+ background-color: #ff4500;
63
+ transform: translateY(-2px);
64
+ }
65
+ button:active {
66
+ transform: translateY(0);
67
+ }
68
+ #history {
69
+ margin-top: 30px;
70
+ }
71
+ .history-item {
72
+ background-color: #fffaf0;
73
+ padding: 15px;
74
+ margin-bottom: 15px;
75
+ border-radius: 8px;
76
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
77
+ }
78
+ .capybara-img {
79
+ max-width: 200px;
80
+ display: block;
81
+ margin: 0 auto 20px;
82
+ border-radius: 50%;
83
+ }
84
+ .quiz-progress {
85
+ text-align: center;
86
+ margin-bottom: 20px;
87
+ font-weight: 600;
88
+ color: #5a3921;
89
+ }
90
+ </style>
91
+ </head>
92
+ <body>
93
+ <div class="container">
94
+ <img src="https://placekitten.com/200/200" alt="Cute Capybara" class="capybara-img">
95
+ <h1>Capybara Dating App Personality Quiz</h1>
96
+ <div id="quiz">
97
+ <div class="quiz-progress">Question <span id="current-question">1</span> of 5</div>
98
+ <div id="question"></div>
99
+ <textarea id="answer" rows="4" placeholder="Type your answer here... Be as honest as a capybara!"></textarea>
100
+ <button id="submit">Next Question</button>
101
+ </div>
102
+ <div id="result" style="display: none;"></div>
103
+ <div id="history"></div>
104
+ </div>
105
+
106
+ <script>
107
+ const API_URL = 'http://localhost:5000';
108
+ let questions = [];
109
+ let answers = [];
110
+ let currentQuestion = '';
111
+
112
+ async function getNextQuestion() {
113
+ const response = await fetch(`${API_URL}/generate_question`, {
114
+ method: 'POST',
115
+ headers: {
116
+ 'Content-Type': 'application/json',
117
+ },
118
+ body: JSON.stringify({ previous_questions: questions, previous_answers: answers }),
119
+ });
120
+ const data = await response.json();
121
+ return data.question;
122
+ }
123
+
124
+ async function classifyPersonality() {
125
+ const response = await fetch(`${API_URL}/classify_personality`, {
126
+ method: 'POST',
127
+ headers: {
128
+ 'Content-Type': 'application/json',
129
+ },
130
+ body: JSON.stringify({ questions, answers }),
131
+ });
132
+ const data = await response.json();
133
+ return data;
134
+ }
135
+
136
+ async function startQuiz() {
137
+ currentQuestion = await getNextQuestion();
138
+ document.getElementById('question').textContent = currentQuestion;
139
+ }
140
+
141
+ document.getElementById('submit').addEventListener('click', async () => {
142
+ const answer = document.getElementById('answer').value.trim();
143
+ if (answer) {
144
+ questions.push(currentQuestion);
145
+ answers.push(answer);
146
+ document.getElementById('history').innerHTML += `
147
+ <div class="history-item">
148
+ <p><strong>Q: ${currentQuestion}</strong></p>
149
+ <p>A: ${answer}</p>
150
+ </div>
151
+ `;
152
+ document.getElementById('answer').value = '';
153
+
154
+ if (questions.length < 5) {
155
+ currentQuestion = await getNextQuestion();
156
+ document.getElementById('question').textContent = currentQuestion;
157
+ document.getElementById('current-question').textContent = questions.length + 1;
158
+ } else {
159
+ const result = await classifyPersonality();
160
+ document.getElementById('quiz').style.display = 'none';
161
+ document.getElementById('result').style.display = 'block';
162
+ document.getElementById('result').innerHTML = `
163
+ <h2>Your Capybara Dating Personality:</h2>
164
+ <p>${result.personality}</p>
165
+ <p>Your personality summary has been saved to: ${result.summary_file}</p>
166
+ <button onclick="location.reload()">Take Quiz Again</button>
167
+ `;
168
+ }
169
+ }
170
+ });
171
+
172
+ startQuiz();
173
+ </script>
174
+ </body>
175
+ </html>
capybara_dating_app_api.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from flask_cors import CORS
3
+ import logging
4
+ from typing import List
5
+ import math
6
+ import faiss
7
+ from langchain_openai import ChatOpenAI, OpenAIEmbeddings
8
+ from langchain_experimental.generative_agents import GenerativeAgent, GenerativeAgentMemory
9
+ from langchain.retrievers import TimeWeightedVectorStoreRetriever
10
+ from langchain_community.vectorstores import FAISS
11
+ from langchain_community.docstore.in_memory import InMemoryDocstore
12
+ from datetime import datetime
13
+ import os
14
+
15
+ app = Flask(__name__)
16
+ CORS(app)
17
+
18
+ # Set up logging and LLM
19
+ logging.basicConfig(level=logging.ERROR)
20
+ LLM = ChatOpenAI(max_tokens=1500)
21
+
22
+ def relevance_score_fn(score: float) -> float:
23
+ return 1.0 - score / math.sqrt(2)
24
+
25
+ def create_new_memory_retriever():
26
+ embeddings_model = OpenAIEmbeddings()
27
+ embedding_size = 1536
28
+ index = faiss.IndexFlatL2(embedding_size)
29
+ vectorstore = FAISS(
30
+ embeddings_model.embed_query,
31
+ index,
32
+ InMemoryDocstore({}),
33
+ {},
34
+ relevance_score_fn=relevance_score_fn,
35
+ )
36
+ return TimeWeightedVectorStoreRetriever(
37
+ vectorstore=vectorstore, other_score_keys=["importance"], k=15
38
+ )
39
+
40
+ PERSONALITY_TYPES = {
41
+ "Romantic Idealist": "Seeks deep emotional connections and believes in soulmates",
42
+ "Adventure Seeker": "Thrives on new experiences and loves to explore",
43
+ "Intellectual Companion": "Values deep conversations and mental stimulation",
44
+ "Social Butterfly": "Energized by social interactions and meeting new people",
45
+ "Nurturing Partner": "Caring, supportive, and focused on emotional well-being",
46
+ "Ambitious Go-Getter": "Driven by goals and seeks a partner with similar ambitions",
47
+ "Creative Spirit": "Expresses themselves through art and values originality",
48
+ "Steady Reliable": "Consistent, dependable, and values stability in relationships"
49
+ }
50
+
51
+ QUESTION_TEMPLATES = [
52
+ "What's your idea of a perfect date?",
53
+ "How do you handle conflicts in a relationship?",
54
+ "What's the most spontaneous thing you've ever done?",
55
+ "How important is personal space to you in a relationship?",
56
+ "What's a deal-breaker for you in a potential partner?",
57
+ "How do you show affection to someone you care about?",
58
+ "What role does humor play in your relationships?",
59
+ "How do you balance your personal goals with a romantic relationship?",
60
+ "What's the most important quality you look for in a partner?",
61
+ "How do you envision your ideal future with a partner?"
62
+ ]
63
+
64
+ class QuestionGeneratorAgent(GenerativeAgent):
65
+ def __init__(self, name: str, age: int, traits: str):
66
+ memory = GenerativeAgentMemory(
67
+ llm=LLM,
68
+ memory_retriever=create_new_memory_retriever(),
69
+ verbose=False,
70
+ reflection_threshold=5
71
+ )
72
+ super().__init__(name=name, age=age, traits=traits, status="active", memory=memory, llm=LLM)
73
+
74
+ def generate_question(self, previous_questions: List[str], previous_answers: List[str]) -> str:
75
+ context = "\n".join([f"Q: {q}\nA: {a}" for q, a in zip(previous_questions, previous_answers)])
76
+ templates = "\n".join([f"- {template}" for template in QUESTION_TEMPLATES])
77
+ prompt = f"""As a dating app personality quiz, generate a new, interesting question based on the following context and question templates:
78
+
79
+ Previous Questions and Answers:
80
+ {context}
81
+
82
+ Question Templates:
83
+ {templates}
84
+
85
+ Create a unique question inspired by these templates, but don't repeat them exactly. The question should be engaging, thought-provoking, and reveal aspects of the person's dating personality. Ensure it's different from the previous questions.
86
+
87
+ Generate only the question, nothing else."""
88
+
89
+ response = self.generate_dialogue_response(prompt)
90
+ return response[1].strip('"') # Remove quotation marks from the response
91
+
92
+ class PersonalityClassifierAgent(GenerativeAgent):
93
+ def __init__(self, name: str, age: int, traits: str):
94
+ memory = GenerativeAgentMemory(
95
+ llm=LLM,
96
+ memory_retriever=create_new_memory_retriever(),
97
+ verbose=False,
98
+ reflection_threshold=5
99
+ )
100
+ super().__init__(name=name, age=age, traits=traits, status="active", memory=memory, llm=LLM)
101
+
102
+ def classify_personality(self, questions: List[str], answers: List[str]) -> dict:
103
+ context = "\n".join([f"Q: {q}\nA: {a}" for q, a in zip(questions, answers)])
104
+ personality_types = "\n".join([f"- {type}: {desc}" for type, desc in PERSONALITY_TYPES.items()])
105
+ prompt = f"""As a dating app personality classifier, categorize the person's dating personality based on these questions and answers:
106
+
107
+ {personality_types}
108
+
109
+ Questions and Answers:
110
+ {context}
111
+
112
+ Provide the personality type and a brief explanation for your choice. Also, suggest potential compatible personality types for dating. Format your response as:
113
+ Personality Type: [chosen type]
114
+ Explanation: [your explanation]
115
+ Compatible Types: [list of compatible types]
116
+ Dating Advice: [brief advice based on their personality type]
117
+ """
118
+ response = self.generate_dialogue_response(prompt)
119
+ personality_summary = response[1]
120
+
121
+ # Save the personality summary to a text file
122
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
123
+ filename = f"personality_summary_{timestamp}.txt"
124
+ with open(filename, "w") as f:
125
+ f.write("Capybara Dating App - Personality Summary\n")
126
+ f.write("=========================================\n\n")
127
+ f.write("Questions and Answers:\n")
128
+ for q, a in zip(questions, answers):
129
+ f.write(f"Q: {q}\n")
130
+ f.write(f"A: {a}\n\n")
131
+ f.write("Personality Classification:\n")
132
+ f.write(personality_summary)
133
+
134
+ return {"personality": personality_summary, "summary_file": filename}
135
+
136
+ question_agent = QuestionGeneratorAgent("CapybaraQuestionBot", 25, "curious, romantic, empathetic")
137
+ classifier_agent = PersonalityClassifierAgent("CapybaraMatchBot", 30, "insightful, compassionate, intuitive")
138
+
139
+ @app.route('/generate_question', methods=['POST'])
140
+ def generate_question():
141
+ data = request.json
142
+ previous_questions = data.get('previous_questions', [])
143
+ previous_answers = data.get('previous_answers', [])
144
+ question = question_agent.generate_question(previous_questions, previous_answers)
145
+ return jsonify({'question': question})
146
+
147
+ @app.route('/classify_personality', methods=['POST'])
148
+ def classify_personality():
149
+ data = request.json
150
+ questions = data.get('questions', [])
151
+ answers = data.get('answers', [])
152
+ result = classifier_agent.classify_personality(questions, answers)
153
+ return jsonify(result)
154
+
155
+ if __name__ == '__main__':
156
+ app.run(debug=True)