michael commited on
Commit Β·
cd7c272
1
Parent(s): 28c3dd4
Update fix ug in risk panel visibiliy
Browse files
app.py
CHANGED
|
@@ -190,7 +190,7 @@ TEMPERATURE_INTERNAL_TASKS = 0
|
|
| 190 |
|
| 191 |
# ββ RAG & Retrieval ββββββββββββββββββββββββββββββββββββββββββ
|
| 192 |
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 193 |
-
DEFAULT_RETRIEVAL_PICKLE_PATH = None
|
| 194 |
|
| 195 |
# Per-scenario system corpus pickle paths.
|
| 196 |
# Set a value to None to fall back to the default RETRIEVAL_PICKLE_PATH.
|
|
@@ -1287,7 +1287,8 @@ def initialize_llm_clients():
|
|
| 1287 |
LLM_CLIENTS["gemini"] = OpenAI(
|
| 1288 |
api_key=gemini_key,
|
| 1289 |
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 1290 |
-
timeout=60.0
|
|
|
|
| 1291 |
)
|
| 1292 |
logger.info("β Gemini client initialized")
|
| 1293 |
|
|
@@ -6748,7 +6749,7 @@ def create_ui(
|
|
| 6748 |
with gr.Column(scale=8):
|
| 6749 |
conversation_panel_title = "### π¬ Conversation"
|
| 6750 |
if show_raghl_default:
|
| 6751 |
-
conversation_panel_title += " | Hover highlighted text to see why it was flagged."
|
| 6752 |
gr.Markdown(conversation_panel_title)
|
| 6753 |
conv_html = gr.HTML(fmt_conversation([], show_tips_default, show_raghl_default, show_pii_hl_default))
|
| 6754 |
warn_html = gr.HTML("")
|
|
@@ -6769,10 +6770,10 @@ def create_ui(
|
|
| 6769 |
# RIGHT: risk panel
|
| 6770 |
right_col_needed = show_risk_default or show_pii_hl_default or (show_infr_default != 0)
|
| 6771 |
with gr.Column(scale=3, visible=right_col_needed) as risk_col:
|
| 6772 |
-
risk_title = gr.Markdown("
|
| 6773 |
-
risk_html
|
| 6774 |
analysis_title = gr.Markdown("### π Analysis", visible=False)
|
| 6775 |
-
infer_card_html = gr.HTML("", visible=
|
| 6776 |
analysis_md = gr.HTML("", visible=False)
|
| 6777 |
|
| 6778 |
# Page-load: apply URL query parameters
|
|
@@ -7010,7 +7011,7 @@ def create_ui(
|
|
| 7010 |
demo_v, # 12. demo_st
|
| 7011 |
demo_prompt, # 13. demo_prompt_st
|
| 7012 |
fmt_conversation([], show_tips_v, show_raghl_v, show_pii_hl_v), # 14. conv_html
|
| 7013 |
-
gr.update(value=
|
| 7014 |
"", # 16. warn_html
|
| 7015 |
gr.update(value="", visible=False), # 17. analysis_md β hidden until first turn
|
| 7016 |
"", # 18. user_tb
|
|
@@ -7034,7 +7035,7 @@ def create_ui(
|
|
| 7034 |
False, # 36. conv_ended_st
|
| 7035 |
gr.update(visible=False), # 37. infer_card_html
|
| 7036 |
scenario_vs, # 38. vs_st
|
| 7037 |
-
gr.update(visible=
|
| 7038 |
gr.update(visible=False), # 40. analysis_title β hidden until first turn
|
| 7039 |
)
|
| 7040 |
|
|
@@ -7235,7 +7236,7 @@ def create_ui(
|
|
| 7235 |
if llm_errored or show_infr_v == 0 or show_infr_v == 2:
|
| 7236 |
infer_card_update = gr.update(visible=False)
|
| 7237 |
else: # show_infr_v == 1: show after each turn
|
| 7238 |
-
infer_card_update = gr.update(value=avatar_html
|
| 7239 |
|
| 7240 |
# ββ Per-card visibility βββββββββββββββββββββββββββββββββββββββββββ
|
| 7241 |
risk_html_val = result[1] if not llm_errored else ""
|
|
@@ -7246,15 +7247,15 @@ def create_ui(
|
|
| 7246 |
|
| 7247 |
return (
|
| 7248 |
result[0], # conv_html
|
| 7249 |
-
gr.update(value=risk_html_val
|
| 7250 |
result[2], # warn_html
|
| 7251 |
gr.update(value=result[3], visible=show_pii_now), # analysis_md (value + visibility)
|
| 7252 |
privacy_html_update, # privacy_settings_html
|
| 7253 |
privacy_group_update, # privacy_settings_group
|
| 7254 |
-
gr.update(
|
| 7255 |
gr.update(visible=show_legend_now), # legend_group
|
| 7256 |
infer_card_update, # infer_card_html
|
| 7257 |
-
gr.update(
|
| 7258 |
gr.update(visible=show_analysis_title_now), # analysis_title
|
| 7259 |
state,
|
| 7260 |
)
|
|
|
|
| 190 |
|
| 191 |
# ββ RAG & Retrieval ββββββββββββββββββββββββββββββββββββββββββ
|
| 192 |
EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"
|
| 193 |
+
DEFAULT_RETRIEVAL_PICKLE_PATH = "./faiss_persona_sarah_chen_retriever_components.pkl" #None
|
| 194 |
|
| 195 |
# Per-scenario system corpus pickle paths.
|
| 196 |
# Set a value to None to fall back to the default RETRIEVAL_PICKLE_PATH.
|
|
|
|
| 1287 |
LLM_CLIENTS["gemini"] = OpenAI(
|
| 1288 |
api_key=gemini_key,
|
| 1289 |
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
| 1290 |
+
timeout=60.0,
|
| 1291 |
+
max_retries=5
|
| 1292 |
)
|
| 1293 |
logger.info("β Gemini client initialized")
|
| 1294 |
|
|
|
|
| 6749 |
with gr.Column(scale=8):
|
| 6750 |
conversation_panel_title = "### π¬ Conversation"
|
| 6751 |
if show_raghl_default:
|
| 6752 |
+
conversation_panel_title += " | Hover over highlighted text to see why it was flagged."
|
| 6753 |
gr.Markdown(conversation_panel_title)
|
| 6754 |
conv_html = gr.HTML(fmt_conversation([], show_tips_default, show_raghl_default, show_pii_hl_default))
|
| 6755 |
warn_html = gr.HTML("")
|
|
|
|
| 6770 |
# RIGHT: risk panel
|
| 6771 |
right_col_needed = show_risk_default or show_pii_hl_default or (show_infr_default != 0)
|
| 6772 |
with gr.Column(scale=3, visible=right_col_needed) as risk_col:
|
| 6773 |
+
risk_title = gr.Markdown("", visible=bool(show_risk_default))
|
| 6774 |
+
risk_html = gr.HTML("", visible=bool(show_risk_default))
|
| 6775 |
analysis_title = gr.Markdown("### π Analysis", visible=False)
|
| 6776 |
+
infer_card_html = gr.HTML("", visible=(show_infr_default != 0))
|
| 6777 |
analysis_md = gr.HTML("", visible=False)
|
| 6778 |
|
| 6779 |
# Page-load: apply URL query parameters
|
|
|
|
| 7011 |
demo_v, # 12. demo_st
|
| 7012 |
demo_prompt, # 13. demo_prompt_st
|
| 7013 |
fmt_conversation([], show_tips_v, show_raghl_v, show_pii_hl_v), # 14. conv_html
|
| 7014 |
+
gr.update(value="", visible=bool(show_risk_v)), # 15. risk_html β empty until first turn, visibility fixed at load
|
| 7015 |
"", # 16. warn_html
|
| 7016 |
gr.update(value="", visible=False), # 17. analysis_md β hidden until first turn
|
| 7017 |
"", # 18. user_tb
|
|
|
|
| 7035 |
False, # 36. conv_ended_st
|
| 7036 |
gr.update(visible=False), # 37. infer_card_html
|
| 7037 |
scenario_vs, # 38. vs_st
|
| 7038 |
+
gr.update(value="", visible=bool(show_risk_v)), # 39. risk_title β empty until first turn, visibility fixed at load
|
| 7039 |
gr.update(visible=False), # 40. analysis_title β hidden until first turn
|
| 7040 |
)
|
| 7041 |
|
|
|
|
| 7236 |
if llm_errored or show_infr_v == 0 or show_infr_v == 2:
|
| 7237 |
infer_card_update = gr.update(visible=False)
|
| 7238 |
else: # show_infr_v == 1: show after each turn
|
| 7239 |
+
infer_card_update = gr.update(value=avatar_html) # node already visible, just set content
|
| 7240 |
|
| 7241 |
# ββ Per-card visibility βββββββββββββββββββββββββββββββββββββββββββ
|
| 7242 |
risk_html_val = result[1] if not llm_errored else ""
|
|
|
|
| 7247 |
|
| 7248 |
return (
|
| 7249 |
result[0], # conv_html
|
| 7250 |
+
gr.update(value=(risk_html_val if show_risk_now else "")), # risk_html (value + visibility)
|
| 7251 |
result[2], # warn_html
|
| 7252 |
gr.update(value=result[3], visible=show_pii_now), # analysis_md (value + visibility)
|
| 7253 |
privacy_html_update, # privacy_settings_html
|
| 7254 |
privacy_group_update, # privacy_settings_group
|
| 7255 |
+
gr.update(), # risk_col β visibility decided once at load; do not re-toggle the parent
|
| 7256 |
gr.update(visible=show_legend_now), # legend_group
|
| 7257 |
infer_card_update, # infer_card_html
|
| 7258 |
+
gr.update(value=("### π‘οΈ Privacy Risk" if show_risk_now else "")), # risk_title
|
| 7259 |
gr.update(visible=show_analysis_title_now), # analysis_title
|
| 7260 |
state,
|
| 7261 |
)
|