Spaces:
Sleeping
Sleeping
Myranda
commited on
Commit
•
e7374ff
1
Parent(s):
06e4f99
Merge pull request #141 from vanderbilt-data-science/138-response_assesment
Browse files- app.py +15 -0
- free_speech_app/FreeSpeechPromptsResponses.py +22 -1
app.py
CHANGED
@@ -180,22 +180,26 @@ if authentication_status:
|
|
180 |
if user_data is None:
|
181 |
|
182 |
draft_response, background_text = generate_custom_response(original_post, chat_mdl, "", "", word_limit)
|
|
|
183 |
|
184 |
st.session_state.draft_response = draft_response.content
|
185 |
st.session_state.background_text = background_text
|
186 |
# st.session_state.sources_text = sources_text
|
187 |
st.session_state.background_info = background_text
|
188 |
# st.session_state.sources = sources_text
|
|
|
189 |
st.rerun()
|
190 |
else:
|
191 |
|
192 |
draft_response, background_text = generate_custom_response(original_post, chat_mdl, user_data['principles'], user_data['writing_style'], word_limit)
|
|
|
193 |
|
194 |
st.session_state.draft_response = draft_response.content
|
195 |
st.session_state.background_text = background_text
|
196 |
# st.session_state.sources_text = sources_text
|
197 |
st.session_state.background_info = background_text
|
198 |
# st.session_state.sources = sources_text
|
|
|
199 |
st.rerun()
|
200 |
|
201 |
# Ensure session state variables are initialized
|
@@ -203,6 +207,8 @@ if authentication_status:
|
|
203 |
st.session_state.draft_response = ''
|
204 |
if 'regenerate_prompt' not in st.session_state:
|
205 |
st.session_state.regenerate_prompt = ''
|
|
|
|
|
206 |
|
207 |
# Output from function
|
208 |
response_textarea = st.text_area(
|
@@ -212,6 +218,13 @@ if authentication_status:
|
|
212 |
key='draft_response_key'
|
213 |
)
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
# Add option to save responses
|
216 |
if st.button("Save This Response"):
|
217 |
#user_data["writing_style"] += st.session_state.draft_response
|
@@ -269,6 +282,8 @@ if authentication_status:
|
|
269 |
updated_response, background_info = regenerate_custom_response(
|
270 |
original_post, chat_mdl, regenerate_prompt, st.session_state.draft_response, regenerate_background, st.session_state.background_text)
|
271 |
st.session_state.draft_response = updated_response.content
|
|
|
|
|
272 |
st.session_state.is_regenerating = False
|
273 |
|
274 |
|
|
|
180 |
if user_data is None:
|
181 |
|
182 |
draft_response, background_text = generate_custom_response(original_post, chat_mdl, "", "", word_limit)
|
183 |
+
response_assessment = assessing_response(chat_mdl, draft_response.content)
|
184 |
|
185 |
st.session_state.draft_response = draft_response.content
|
186 |
st.session_state.background_text = background_text
|
187 |
# st.session_state.sources_text = sources_text
|
188 |
st.session_state.background_info = background_text
|
189 |
# st.session_state.sources = sources_text
|
190 |
+
st.session_state.response_assessment = response_assessment
|
191 |
st.rerun()
|
192 |
else:
|
193 |
|
194 |
draft_response, background_text = generate_custom_response(original_post, chat_mdl, user_data['principles'], user_data['writing_style'], word_limit)
|
195 |
+
response_assessment = assessing_response(chat_mdl, draft_response.content)
|
196 |
|
197 |
st.session_state.draft_response = draft_response.content
|
198 |
st.session_state.background_text = background_text
|
199 |
# st.session_state.sources_text = sources_text
|
200 |
st.session_state.background_info = background_text
|
201 |
# st.session_state.sources = sources_text
|
202 |
+
st.session_state.response_assessment = response_assessment.content
|
203 |
st.rerun()
|
204 |
|
205 |
# Ensure session state variables are initialized
|
|
|
207 |
st.session_state.draft_response = ''
|
208 |
if 'regenerate_prompt' not in st.session_state:
|
209 |
st.session_state.regenerate_prompt = ''
|
210 |
+
if 'response_assessment' not in st.session_state:
|
211 |
+
st.session_state.response_assessment = ''
|
212 |
|
213 |
# Output from function
|
214 |
response_textarea = st.text_area(
|
|
|
218 |
key='draft_response_key'
|
219 |
)
|
220 |
|
221 |
+
# Assessment of the response
|
222 |
+
response_assessment = st.text_area(
|
223 |
+
label="Assessment of the Response",
|
224 |
+
value=st.session_state.response_assessment if 'response_assessment' in st.session_state else '',
|
225 |
+
height=350,
|
226 |
+
key='response_assessment_key'
|
227 |
+
)
|
228 |
# Add option to save responses
|
229 |
if st.button("Save This Response"):
|
230 |
#user_data["writing_style"] += st.session_state.draft_response
|
|
|
282 |
updated_response, background_info = regenerate_custom_response(
|
283 |
original_post, chat_mdl, regenerate_prompt, st.session_state.draft_response, regenerate_background, st.session_state.background_text)
|
284 |
st.session_state.draft_response = updated_response.content
|
285 |
+
updated_response_assessment = assessing_response(chat_mdl, updated_response).content
|
286 |
+
st.session_state.response_assessment = updated_response_assessment
|
287 |
st.session_state.is_regenerating = False
|
288 |
|
289 |
|
free_speech_app/FreeSpeechPromptsResponses.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
# %% auto 0
|
4 |
__all__ = ['DEAFULT_PROMPT_TEMPLATE_TEXT', 'query_retriever', 'get_chat_model_response', 'call_chatGPT', 'generate_custom_prompt',
|
5 |
-
'generate_custom_response', 'regenerate_custom_response']
|
6 |
|
7 |
# %% ../nbs/free-speech-prompts.ipynb 5
|
8 |
# libraries required for functionality
|
@@ -128,3 +128,24 @@ def regenerate_custom_response(original_post, chat_mdl, regenerate_prompt, draft
|
|
128 |
updated_response = get_chat_model_response(chat_mdl, customized_prompt)
|
129 |
|
130 |
return updated_response, background_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# %% auto 0
|
4 |
__all__ = ['DEAFULT_PROMPT_TEMPLATE_TEXT', 'query_retriever', 'get_chat_model_response', 'call_chatGPT', 'generate_custom_prompt',
|
5 |
+
'generate_custom_response', 'regenerate_custom_response', 'assessing_response']
|
6 |
|
7 |
# %% ../nbs/free-speech-prompts.ipynb 5
|
8 |
# libraries required for functionality
|
|
|
128 |
updated_response = get_chat_model_response(chat_mdl, customized_prompt)
|
129 |
|
130 |
return updated_response, background_info
|
131 |
+
|
132 |
+
# %% ../nbs/free-speech-prompts.ipynb 15
|
133 |
+
def assessing_response(chat_mdl, draft_response):
|
134 |
+
|
135 |
+
guidelines = '''1. Keep your response short and to the point.
|
136 |
+
2. Use either a humorous or empathetic tone - depending on the situation.
|
137 |
+
For instance, an empathetic response could be "This post is very painful for Jewish people to read".
|
138 |
+
A humorous response could be the use of sarcasm to discredit the hate speech.
|
139 |
+
3. Promote positive dialogue and community building. Encourage constructive, respectful, and emphathetic response.
|
140 |
+
4. Keep the response as fact-based and well-reasoned.
|
141 |
+
5. Showcase the importance of unity, tolerance, and coexistence to counteract the negative narratives.
|
142 |
+
6. Always keep the aforementioned context in mind.
|
143 |
+
7. Acknowledge individual's inherent worth and dignity. '''
|
144 |
+
|
145 |
+
# create customized prompt
|
146 |
+
customized_prompt = f"You are a unbiased agent reviewing on quality of response towards hate speech. Here is a list of best practices when responding to hate speech: {guidelines}. Please provide feedback on how well the response adheres to these guidelines. Here is the original response: {draft_response}. Please limit the feedback to no more than 100 words."
|
147 |
+
|
148 |
+
# get response
|
149 |
+
response_assessment = get_chat_model_response(chat_mdl, customized_prompt)
|
150 |
+
|
151 |
+
return response_assessment
|