Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,8 @@ 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('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)
|
@@ -63,6 +65,12 @@ trait_content_df_org=pd.read_csv('AI Personality Chart trait_content.csv')
|
|
63 |
trait_content_df_org=trait_content_df_org.drop(0,axis=0)
|
64 |
trait_content_df_org.rename(columns={'Column 1':'Question','Column 2':'Options','Column 3':'Traits','Column 4':'Content'},inplace=True)
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def ui():
|
68 |
# Initialize a dictionary to store responses
|
@@ -97,11 +105,11 @@ def ui():
|
|
97 |
st.write(question)
|
98 |
st.write(selected_option)
|
99 |
|
100 |
-
#
|
101 |
selected_traits = [responses[question] for question in responses]
|
102 |
options_list = []
|
103 |
traits_list = []
|
104 |
-
content_list = []
|
105 |
|
106 |
for trait_str in selected_traits:
|
107 |
matching_rows = trait_content_df_org[trait_content_df_org["Options"] == trait_str]
|
@@ -109,24 +117,24 @@ def ui():
|
|
109 |
if not matching_rows.empty:
|
110 |
options_list.append(matching_rows["Options"].values[0])
|
111 |
traits_list.append(matching_rows["Traits"].values[0])
|
112 |
-
content_list.append(matching_rows["Content"].values[0])
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
|
116 |
# Display user input field
|
117 |
name_input = st.text_input("Enter your name:")
|
118 |
|
119 |
# Add a submit button
|
120 |
if st.button("Submit"):
|
121 |
-
# Generate a chatbot response
|
|
|
122 |
bio = conversational_chat(prompt, name_input)
|
123 |
st.write(bio)
|
124 |
|
125 |
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
if __name__=='__main__':
|
132 |
ui()
|
|
|
12 |
from langchain.memory import ConversationBufferWindowMemory
|
13 |
from langchain.chains import ConversationalRetrievalChain
|
14 |
|
15 |
+
os.environ["OPENAI_API_KEY"] ='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'
|
16 |
+
|
17 |
trait_content_df=pd.read_csv('AI Personality Chart trait_content.csv')
|
18 |
trait_content_df=trait_content_df.drop(0,axis=0)
|
19 |
trait_content_df.rename(columns={'Column 1':'Question','Column 2':'Options','Column 3':'Traits','Column 4':'Content'},inplace=True)
|
|
|
65 |
trait_content_df_org=trait_content_df_org.drop(0,axis=0)
|
66 |
trait_content_df_org.rename(columns={'Column 1':'Question','Column 2':'Options','Column 3':'Traits','Column 4':'Content'},inplace=True)
|
67 |
|
68 |
+
# Import the second CSV file
|
69 |
+
traits_description_df = pd.read_csv('Traits Description - Sheet1.csv')
|
70 |
+
|
71 |
+
# Extract unique values from the "Traits" column of trait_content_df_org
|
72 |
+
unique_traits = trait_content_df_org['Traits'].unique()
|
73 |
+
|
74 |
|
75 |
def ui():
|
76 |
# Initialize a dictionary to store responses
|
|
|
105 |
st.write(question)
|
106 |
st.write(selected_option)
|
107 |
|
108 |
+
# Extract traits from the selected options
|
109 |
selected_traits = [responses[question] for question in responses]
|
110 |
options_list = []
|
111 |
traits_list = []
|
112 |
+
# content_list = []
|
113 |
|
114 |
for trait_str in selected_traits:
|
115 |
matching_rows = trait_content_df_org[trait_content_df_org["Options"] == trait_str]
|
|
|
117 |
if not matching_rows.empty:
|
118 |
options_list.append(matching_rows["Options"].values[0])
|
119 |
traits_list.append(matching_rows["Traits"].values[0])
|
|
|
120 |
|
121 |
+
# Get unique traits from the selected options
|
122 |
+
unique_traits = list(set(traits_list))
|
123 |
+
|
124 |
+
# Create a content list as a formatted string
|
125 |
+
formatted_content_list = ",".join([f"'{trait.lower()}'" for trait in unique_traits])
|
126 |
|
127 |
# Display user input field
|
128 |
name_input = st.text_input("Enter your name:")
|
129 |
|
130 |
# Add a submit button
|
131 |
if st.button("Submit"):
|
132 |
+
# Generate a chatbot response using the formatted content list as part of the prompt
|
133 |
+
prompt = f"The following are Traits {formatted_content_list}"
|
134 |
bio = conversational_chat(prompt, name_input)
|
135 |
st.write(bio)
|
136 |
|
137 |
|
138 |
|
|
|
|
|
|
|
|
|
139 |
if __name__=='__main__':
|
140 |
ui()
|