Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- AI Personality Chart trait_content.csv +36 -0
- app.py +133 -0
- requirements.txt +4 -0
AI Personality Chart trait_content.csv
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Title,Column 1,Column 2,Column 3,Column 4
|
2 |
+
,Question,Options,Traits,Content
|
3 |
+
1 Mandatory,"vibrant nightlife but poor air quality, or a city with clean air but a dull nightlife",A) vibrant nightlife but poor air quality,"Extrovert, Short term",You’d rather drown in the excitement of life if it reminds you that you’re alive. You are often perceived as selfish.
|
4 |
+
,,B) a city with clean air but a dull nightlife,"Introvert, Long term","You do it not for validation of others, you do it so you can look yourself in the mirror. "
|
5 |
+
2 Mandatory,Would you rather have a million dollars or restart your life at 16 years of age,A) have a million dollars,"Security, Reliability, Practical, Thinking, Seeks control",You're someone who values financial security and stability. You're willing to work hard to achieve your goals and you prioritize financial success.
|
6 |
+
,,B) restart your life at 16 years of age,"Passion, Novelty, emotional, Feeling, Seeks freedom","Valuing personal growth, your emotional self is restless, independent and always in pursuit of finding new ways to feel."
|
7 |
+
3 Mandatory,fly once or learn any language fluently,A) fly once,"Passion, Novelty, Feeling, Individualistic, Extrovert, Short Term","Passionate as you are, you use creativity to win others’ attention. You may sometimes come across as overbearing though. "
|
8 |
+
,,B) learn any language fluently,"Security, Thinking, Long term, Collectivist, Introvert","You believe that knowledge is power and you prioritize learning new things that you can utilize in the long run. Sometimes looking far ahead, you may often forget to breathe."
|
9 |
+
4 Mandatory,communicate with animals or be able to control the weather ,A) communicate with animals,"Feeling, Collectivist, Seeks freedom, Optimistic",You're an empath who values connection. You are curious about how to help people and what feels like home.
|
10 |
+
,,B) be able to control the weather,"Thinking, Individualistic, Seeks Control, Nihilistic","You're someone who is individualistic af. You prioritize taking charge of your own life, even when you think everything else is doomed. "
|
11 |
+
5 Mandatory,1 crore right away or 50% chance of 10 crores,A) 1 crore right away,"Short-term, Practical","You find it hard to keep money. Thinking short-term is sometimes a necessity, not a choice."
|
12 |
+
,,B) 50% chance of 10 crores,"Long-term, Feeling",You value long-term planning. This makes you idealistic af or just lucky.
|
13 |
+
6 Mandatory,old age but forgotten or die young but famous,A) old age but forgotten,"Long Term, Collectivist, Security",You find yourself to be happy among the people who love you even if you can count them on your fingers.
|
14 |
+
,,B) die young but famous,"Short-term, Individualistic, Vitality",It’s not you don’t value relationships. You just sometimes take them for granted.
|
15 |
+
7 Optional,"Gorgeous building Ugly view, Ugly building gorgeous view",A) Gorgeous building Ugly view,"Extrovert, Power, Adventure",For you everything that a human being can offer is “natural” even when it’s fabricated.
|
16 |
+
,,B) Ugly building gorgeous view,"Introvert, Utility, Feeling,",You prioritize function over form and stare deep into the abyss even when it sometimes hurts your own eyes.
|
17 |
+
8 Optional,Would you rather be able to fly or be invisible,A) be able to fly,"Extrovert, Passion, Feeling","You've the courage to seek beyond the norm, even at the cost of being misunderstood. "
|
18 |
+
,,B) be invisible,"introvert, thinking, Practical","You may be introverted, preferring to observe and analyze situations from far away rather than be the center of attention."
|
19 |
+
9 Optional,Would you rather be able to Read minds or speak any language fluently,A) Read minds,"Thinking, Individualistic, Novelty, Seeks control",You desire power and control so that you can lead by example those who desire to be led.
|
20 |
+
,,B) speak any language fluently,"Feeling, Collectivist, Reliability, Seeks freedom","You believe that knowledge is power, and it’s all you need to start a commune."
|
21 |
+
10 Optional,Would you rather be eaten by a shark or mauled by a bear,A) Eaten by a shark,Sea Water,You question all things seemingly mysterious. You take pride in your ability to make people feel better when they’re blue
|
22 |
+
,,B) Mauled by a bear,Mountain Forest,You’re fundamentally bold and proud. You love attention and to be cared for.
|
23 |
+
11 Optional,Would you rather have Pets/children,A) pets,"Seeks Freedom, Individualistic, Novelty",You're someone who values independence and freedom. You prioritize personal expression and believe that individuality is important.
|
24 |
+
,,B) children,"Seeks Control, Collectivist, Reliability",You're someone who values relationships and connection. You prioritize building meaningful connections with others over personal freedom or independence.
|
25 |
+
12 Optional,Get a tattoo or become a parent,A) get a tattoo,"Seeks Freedom, Individualistic, Novelty",You're someone who values personal expression and creativity sometimes at the cost of being correct.
|
26 |
+
,,B) become a parent,"Seeks Control, Collectivist, Reliability",You prioritize building meaningful connections with others over personal expression or creativity.
|
27 |
+
13 Optional,Eat without gaining weight or have endless energy,A) eat without gaining weight,"Feeling, Short-term, ",You're someone who is super passionate and a “feeler” You find it hard to plan for the future.
|
28 |
+
,,B) have endless energy,"Thinking, Long-term","You insist that being useful is important, sometimes even at the cost of being misunderstood."
|
29 |
+
14 Optional,"laid back job that pays well, or your own startup that makes no money",A) laid back job that pays well,"Security, Reliability, Seeks Control",You're someone who values stability and security. You prioritize having a steady income and believe that financial stability is important.
|
30 |
+
,,B) your own startup that makes no money,"Novelty, Vitality, Seeks Freedom","You seek independence over material pleasure. You realize that faith needs to be cultivated, but it takes a lot of courage to have faith."
|
31 |
+
15 Optional,Would you rather be poor with a family or rich and lonely?,A) Poor with family,"Collectivist, Family, feeling",To you a broken house that is full of love is more important than an empty castle.
|
32 |
+
,,B) Rich but lonely,"Individualistic, power, thinking",You juggle the idealism of independence and the realism of the material stability like a magician.
|
33 |
+
16 Optional,Would express my body like: movement is rhythm b) stiff but comfy,A) movement is rhythm,"Individualistic, Seeks freedom, Long-term",You hold your ground to your principles even at the cost of being alone.
|
34 |
+
,,B) stiff but comfy,"Collectivist, Seeks control, Short-term",You're someone who values comfort and practicality sometimes at the cost of your long-term health.
|
35 |
+
17 Optional,"Would you rather be able to read and write in any language, or have infinite memory",A) be able to read and write in any language,"Diversity, Collectivism",You value diversity and collectivism. You come across as serious and rational when dealing with conflict
|
36 |
+
,,B) have infinite memory,"Powerless, Messy Situations",You feel powerless to fix messy situations so you often tend to take a step back
|
app.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import langchain
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import os
|
6 |
+
|
7 |
+
import re
|
8 |
+
|
9 |
+
from langchain.chat_models import ChatOpenAI
|
10 |
+
import openai
|
11 |
+
from langchain import HuggingFaceHub, LLMChain, PromptTemplate
|
12 |
+
from langchain.memory import ConversationBufferWindowMemory
|
13 |
+
from langchain.chains import ConversationalRetrievalChain
|
14 |
+
|
15 |
+
trait_content_df=pd.read_csv(r'C:\codes\Dahila UI\AI Personality Chart trait_content.csv')
|
16 |
+
trait_content_df=trait_content_df.drop(0,axis=0)
|
17 |
+
trait_content_df.rename(columns={'Column 1':'Question','Column 2':'Options','Column 3':'Traits','Column 4':'Content'},inplace=True)
|
18 |
+
trait_content_df['Title'].fillna(method='ffill',inplace=True)
|
19 |
+
trait_content_df['Question'].fillna(method='ffill',inplace=True)
|
20 |
+
|
21 |
+
template = """
|
22 |
+
You are given options selected by user for a particular question indirectly related to the personality with the traits detected.
|
23 |
+
You task is to create a personalized dating app bio for the user, Don't Includes option in the answer use it as reference for answer generation. Limit the answer in not more than 100 words
|
24 |
+
{history}
|
25 |
+
Me:{human_input}
|
26 |
+
Jack:
|
27 |
+
"""
|
28 |
+
prompt = PromptTemplate(
|
29 |
+
input_variables=["history", "human_input"],
|
30 |
+
template=template
|
31 |
+
)
|
32 |
+
|
33 |
+
llm_chain = LLMChain(
|
34 |
+
llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo'),
|
35 |
+
prompt=prompt,
|
36 |
+
verbose=True,
|
37 |
+
memory=ConversationBufferWindowMemory(k=2)
|
38 |
+
)
|
39 |
+
|
40 |
+
def extract_text_from_html(html):
|
41 |
+
cleanr = re.compile('<.*?>')
|
42 |
+
cleantext = re.sub(cleanr, '', html)
|
43 |
+
return cleantext.strip()
|
44 |
+
|
45 |
+
def conversational_chat(query, replacement_word=None):
|
46 |
+
hist_dict['past'].append(query)
|
47 |
+
output = llm_chain.predict(human_input=query)
|
48 |
+
hist_dict['generated'].append(output)
|
49 |
+
|
50 |
+
if replacement_word is not None:
|
51 |
+
# Use a regular expression with the re module for case-insensitive replacement
|
52 |
+
output = re.sub(r'\bjack\b', replacement_word, output, flags=re.IGNORECASE)
|
53 |
+
|
54 |
+
return extract_text_from_html(output)
|
55 |
+
|
56 |
+
|
57 |
+
|
58 |
+
hist_dict={}
|
59 |
+
hist_dict['generated']=["Hello ! Ask me anything about " + " 🤗"]
|
60 |
+
hist_dict['past'] = ["Hey ! 👋"]
|
61 |
+
os.environ["OPENAI_API_KEY"] ='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'
|
62 |
+
|
63 |
+
trait_content_df_org=pd.read_csv(r'C:\codes\Dahila UI\AI Personality Chart trait_content.csv')
|
64 |
+
trait_content_df_org=trait_content_df_org.drop(0,axis=0)
|
65 |
+
trait_content_df_org.rename(columns={'Column 1':'Question','Column 2':'Options','Column 3':'Traits','Column 4':'Content'},inplace=True)
|
66 |
+
|
67 |
+
|
68 |
+
def ui():
|
69 |
+
# Initialize a dictionary to store responses
|
70 |
+
responses = {}
|
71 |
+
|
72 |
+
# Create checkboxes for each question and options
|
73 |
+
index = 0
|
74 |
+
while index < len(trait_content_df_org):
|
75 |
+
question = trait_content_df_org.iloc[index]["Question"]
|
76 |
+
st.write(question)
|
77 |
+
|
78 |
+
option_a = st.checkbox(f"Option A: {trait_content_df_org.iloc[index]['Options']}", key=f"option_a_{index}")
|
79 |
+
|
80 |
+
# Check if Option B has a corresponding question (not None)
|
81 |
+
if trait_content_df_org.iloc[index + 1]["Question"] is not None:
|
82 |
+
option_b = st.checkbox(f"Option B: {trait_content_df_org.iloc[index + 1]['Options']}", key=f"option_b_{index + 1}")
|
83 |
+
else:
|
84 |
+
option_b = False
|
85 |
+
|
86 |
+
st.write("") # Add some spacing between questions
|
87 |
+
|
88 |
+
# Store responses in the dictionary
|
89 |
+
if option_a:
|
90 |
+
responses[question] = f"{trait_content_df_org.iloc[index]['Options']}"
|
91 |
+
if option_b:
|
92 |
+
responses[question] = f"{trait_content_df_org.iloc[index + 1]['Options']}"
|
93 |
+
|
94 |
+
index += 2 # Move to the next question and options (skipping None)
|
95 |
+
|
96 |
+
st.write("Responses:")
|
97 |
+
for question, selected_option in responses.items():
|
98 |
+
st.write(question)
|
99 |
+
st.write(selected_option)
|
100 |
+
|
101 |
+
# Generate a prompt based on selected options
|
102 |
+
selected_traits = [responses[question] for question in responses]
|
103 |
+
options_list = []
|
104 |
+
traits_list = []
|
105 |
+
content_list = []
|
106 |
+
|
107 |
+
for trait_str in selected_traits:
|
108 |
+
matching_rows = trait_content_df_org[trait_content_df_org["Options"] == trait_str]
|
109 |
+
|
110 |
+
if not matching_rows.empty:
|
111 |
+
options_list.append(matching_rows["Options"].values[0])
|
112 |
+
traits_list.append(matching_rows["Traits"].values[0])
|
113 |
+
content_list.append(matching_rows["Content"].values[0])
|
114 |
+
|
115 |
+
prompt = f"Options selected are {', '.join(options_list)}. The following are Traits {{{', '.join(traits_list)}}}, and the content for the options is {', '.join(content_list)}"
|
116 |
+
|
117 |
+
# Display user input field
|
118 |
+
name_input = st.text_input("Enter your name:")
|
119 |
+
|
120 |
+
# Add a submit button
|
121 |
+
if st.button("Submit"):
|
122 |
+
# Generate a chatbot response
|
123 |
+
bio = conversational_chat(prompt, name_input)
|
124 |
+
st.write(bio)
|
125 |
+
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
+
if __name__=='__main__':
|
133 |
+
ui()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
langchain
|
3 |
+
openai
|
4 |
+
tiktoken
|