Spaces:
Sleeping
Sleeping
Myranda
commited on
Commit
•
2c9c4d1
1
Parent(s):
587e02a
Merge pull request #162 from vanderbilt-data-science/survey
Browse files- app.py +16 -8
- requirements.txt +1 -0
app.py
CHANGED
@@ -5,10 +5,11 @@ import yaml
|
|
5 |
from yaml.loader import SafeLoader
|
6 |
import os
|
7 |
from cryptography.fernet import Fernet
|
8 |
-
|
9 |
from free_speech_app.DataLoadDb import *
|
10 |
from free_speech_app.FreeSpeechPromptsResponses import *
|
11 |
from langchain.chat_models import ChatOpenAI
|
|
|
12 |
|
13 |
|
14 |
#connect to/create Deta user database
|
@@ -90,6 +91,16 @@ if authentication_status:
|
|
90 |
org_principles = str(file.read())
|
91 |
|
92 |
if page == "Account Setup":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
st.title("Account Setup")
|
95 |
st.markdown("Please use this page to provide your OpenAI API Key, Principles and Writing Style. **Please make sure to press the Save Changes button after providing the information.**")
|
@@ -103,17 +114,14 @@ if authentication_status:
|
|
103 |
encrypted_api_key = str(encrypt(api_input, fernet))
|
104 |
st.session_state.api_key = api_input
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
user_principles = user_principles + "\n" + org_principles
|
109 |
-
|
110 |
-
principles = st.text_area("My Principles (Paste Principles here. If you affiliated with a registered organization, these principles will also appear here.)", height = 300, placeholder = "Think about the hate speech you want to counter. What makes you want to write back? Note any principles that are true to your heart, from an abstract thought to a well-defined concept. For ideas, consider: a theory, philosophy, law, policy, workplace professional ethic, cultural norm, family value, idiomatic saying, colloquialism, life lesson, habit, intuition, literary or artistic expression, fortune cookie message, etc.", value=user_principles)
|
111 |
writing_style = st.text_area("My Writing Style (Paste Examples)", height = 300, placeholder = "Provide examples of your writing style here", value=user_data["writing_style"] if user_data and "writing_style" in user_data else "")
|
112 |
#sources = st.text_area("Sources (This autopopulates for your reference)", value=st.session_state.sources if 'sources' in st.session_state else '', key = 'sources_key', height = 100)
|
113 |
|
114 |
# Update button
|
115 |
if st.button("Save Changes"):
|
116 |
-
db.put({"key": username, "principles": principles, "writing_style": writing_style, "api_key": encrypted_api_key})
|
117 |
|
118 |
if page == "API Key Help":
|
119 |
|
@@ -233,7 +241,7 @@ if authentication_status:
|
|
233 |
principles = user_data["principles"] if user_data and "principles" in user_data else ""
|
234 |
encrypted_api_key = str(encrypt(st.session_state.api_key, fernet))
|
235 |
|
236 |
-
db.put({"key": username, "writing_style": writing_style, "principles": principles,"api_key": encrypted_api_key})
|
237 |
st.write("Response saved to your writing style.")
|
238 |
|
239 |
# Assessment of the response
|
|
|
5 |
from yaml.loader import SafeLoader
|
6 |
import os
|
7 |
from cryptography.fernet import Fernet
|
8 |
+
import streamlit_survey as ss
|
9 |
from free_speech_app.DataLoadDb import *
|
10 |
from free_speech_app.FreeSpeechPromptsResponses import *
|
11 |
from langchain.chat_models import ChatOpenAI
|
12 |
+
import json as json_module
|
13 |
|
14 |
|
15 |
#connect to/create Deta user database
|
|
|
91 |
org_principles = str(file.read())
|
92 |
|
93 |
if page == "Account Setup":
|
94 |
+
|
95 |
+
if not user_data or user_data.get('login_count') in [None, 0]:
|
96 |
+
survey = ss.StreamlitSurvey("Please answer the following questions to help define your principles")
|
97 |
+
survey.text_input("Who would you identify as a hero or exemplar, fictional or real, whose moral courage reflects what you also believe in? Why?", id="Q1")
|
98 |
+
survey.text_input("What is an instance of hate that would cross a line for you, making you feel a need to respond?", id="Q2")
|
99 |
+
survey.text_input("Given your character, how would you seek to address the harms of hate (i.e., to educate, persuade, deescalate, forgive, repair, etc.)?", id="Q3")
|
100 |
+
json_string = survey.to_json()
|
101 |
+
json_dict = json_module.loads(json_string)
|
102 |
+
survey_responses = json_dict["Q1"]["value"] + " " + json_dict["Q2"]["value"] + " " + json_dict["Q3"]["value"]
|
103 |
+
|
104 |
|
105 |
st.title("Account Setup")
|
106 |
st.markdown("Please use this page to provide your OpenAI API Key, Principles and Writing Style. **Please make sure to press the Save Changes button after providing the information.**")
|
|
|
114 |
encrypted_api_key = str(encrypt(api_input, fernet))
|
115 |
st.session_state.api_key = api_input
|
116 |
|
117 |
+
principles = st.text_area("My Principles (Enter or autopopulates from questions above)", height = 300, value= user_data["principles"] +"\n" + org_principles if user_data and "principles" in user_data and user_data["principles"].strip() != "" else survey_responses + "\n" + org_principles)
|
118 |
+
|
|
|
|
|
|
|
119 |
writing_style = st.text_area("My Writing Style (Paste Examples)", height = 300, placeholder = "Provide examples of your writing style here", value=user_data["writing_style"] if user_data and "writing_style" in user_data else "")
|
120 |
#sources = st.text_area("Sources (This autopopulates for your reference)", value=st.session_state.sources if 'sources' in st.session_state else '', key = 'sources_key', height = 100)
|
121 |
|
122 |
# Update button
|
123 |
if st.button("Save Changes"):
|
124 |
+
db.put({"key": username, "principles": principles, "writing_style": writing_style, "api_key": encrypted_api_key, "login_count": 0 if principles.strip() == "" else 1})
|
125 |
|
126 |
if page == "API Key Help":
|
127 |
|
|
|
241 |
principles = user_data["principles"] if user_data and "principles" in user_data else ""
|
242 |
encrypted_api_key = str(encrypt(st.session_state.api_key, fernet))
|
243 |
|
244 |
+
db.put({"key": username, "writing_style": writing_style, "principles": principles,"api_key": encrypted_api_key, "login_count": 0 if principles.strip() == "" else 1})
|
245 |
st.write("Response saved to your writing style.")
|
246 |
|
247 |
# Assessment of the response
|
requirements.txt
CHANGED
@@ -10,3 +10,4 @@ chromadb
|
|
10 |
tiktoken
|
11 |
unstructured
|
12 |
nltk
|
|
|
|
10 |
tiktoken
|
11 |
unstructured
|
12 |
nltk
|
13 |
+
streamlit_survey
|