Michael commited on
Commit ·
325ea48
1
Parent(s): c41f4e6
Bug fixes.
Browse files
app.py
CHANGED
|
@@ -6159,22 +6159,22 @@ def fmt_conversation(messages, show_tips=True, show_rag_hl=True, show_pii_hl=Tru
|
|
| 6159 |
# visibility + opacity are delayed 0.7 s before hiding so the user has
|
| 6160 |
# time to move the mouse from the anchor into the popup.
|
| 6161 |
".tt-popup{opacity:0;visibility:hidden;pointer-events:auto;"
|
| 6162 |
-
"position:
|
| 6163 |
"border:2px solid #bbb;border-radius:10px;padding:10px 12px;width:max-content;"
|
| 6164 |
"max-width:min(500px,calc(100vw - 40px));box-shadow:0 8px 20px rgba(0,0,0,0.15);font-family:inherit;"
|
| 6165 |
"font-size:0.7em!important;line-height:1.25!important;text-align:left;"
|
| 6166 |
-
"bottom:
|
| 6167 |
"transition:opacity 0s 0.15s,visibility 0s 0.15s;}"
|
| 6168 |
|
| 6169 |
# Prevent tooltip from going beyond left edge
|
| 6170 |
-
".tt-popup{left:max(10px,min(50%,calc(100% - 10px)));transform:translateX(min(0px,max(-100%,calc(-50% - 10px))));}"
|
| 6171 |
|
| 6172 |
# Show immediately on anchor hover OR when mouse is on the popup itself.
|
| 6173 |
# Both paths are always reachable because pointer-events is never none.
|
| 6174 |
".tt-anchor:hover .tt-popup,.tt-popup:hover{opacity:1;visibility:visible;transition:opacity 0s 0s,visibility 0s 0s;}"
|
| 6175 |
|
| 6176 |
# Position below when near top
|
| 6177 |
-
".tt-anchor.near-top .tt-popup{bottom:auto;top:calc(100% + 8px);}"
|
| 6178 |
|
| 6179 |
"""
|
| 6180 |
/* Override Gradio theme variables */
|
|
@@ -6262,35 +6262,6 @@ def fmt_conversation(messages, show_tips=True, show_rag_hl=True, show_pii_hl=Tru
|
|
| 6262 |
|
| 6263 |
"</style>"
|
| 6264 |
|
| 6265 |
-
# Minimal JavaScript for near-top detection
|
| 6266 |
-
"<script>"
|
| 6267 |
-
"document.addEventListener('DOMContentLoaded',function(){"
|
| 6268 |
-
# near-top repositioning (unchanged)
|
| 6269 |
-
"setInterval(function(){"
|
| 6270 |
-
"document.querySelectorAll('.tt-anchor').forEach(function(el){"
|
| 6271 |
-
"var rect=el.getBoundingClientRect();"
|
| 6272 |
-
"if(rect.top<window.innerHeight*0.3){el.classList.add('near-top');}else{el.classList.remove('near-top');}"
|
| 6273 |
-
"});},200);"
|
| 6274 |
-
# Double-click to pin/unpin
|
| 6275 |
-
"document.addEventListener('dblclick',function(e){"
|
| 6276 |
-
"var anchor=e.target.closest('.tt-anchor');"
|
| 6277 |
-
"if(anchor){"
|
| 6278 |
-
"var popup=anchor.querySelector('.tt-popup');"
|
| 6279 |
-
"if(!popup)return;"
|
| 6280 |
-
"var pinned=anchor.classList.toggle('tt-pin-active');"
|
| 6281 |
-
"popup.classList.toggle('tt-pinned',pinned);"
|
| 6282 |
-
"e.preventDefault();"
|
| 6283 |
-
"}});"
|
| 6284 |
-
# Click anywhere outside a pinned tooltip to dismiss it
|
| 6285 |
-
"document.addEventListener('click',function(e){"
|
| 6286 |
-
"if(!e.target.closest('.tt-pin-active')){"
|
| 6287 |
-
"document.querySelectorAll('.tt-anchor.tt-pin-active').forEach(function(a){"
|
| 6288 |
-
"a.classList.remove('tt-pin-active');"
|
| 6289 |
-
"a.querySelectorAll('.tt-popup').forEach(function(p){p.classList.remove('tt-pinned');});"
|
| 6290 |
-
"});}"
|
| 6291 |
-
"});"
|
| 6292 |
-
"});"
|
| 6293 |
-
"</script>"
|
| 6294 |
)
|
| 6295 |
h = [css, '<div class="chat-box">']
|
| 6296 |
for m in messages:
|
|
@@ -6568,7 +6539,7 @@ def create_ui(
|
|
| 6568 |
|
| 6569 |
|
| 6570 |
# CENTER: conversation
|
| 6571 |
-
with gr.Column(scale=
|
| 6572 |
conversation_panel_title = "### 💬 Conversation"
|
| 6573 |
if show_raghl_default:
|
| 6574 |
conversation_panel_title += " | Hover highlighted text to see why it was flagged."
|
|
@@ -6591,7 +6562,7 @@ def create_ui(
|
|
| 6591 |
|
| 6592 |
# RIGHT: risk panel
|
| 6593 |
right_col_needed = show_risk_default or show_pii_hl_default or (show_infr_default != 0)
|
| 6594 |
-
with gr.Column(scale=
|
| 6595 |
risk_title = gr.Markdown("### 🛡️ Privacy Risk", visible=False)
|
| 6596 |
risk_html = gr.HTML(create_risk_display(0), visible=False)
|
| 6597 |
analysis_title = gr.Markdown("### 📝 Analysis", visible=False)
|
|
@@ -7204,7 +7175,7 @@ if __name__ == "__main__":
|
|
| 7204 |
color-scheme:light!important}
|
| 7205 |
.gradio-container{background:#fff!important}
|
| 7206 |
.dark .gradio-container{background:#fff!important}
|
| 7207 |
-
.gradio-container,.gradio-container *{font-size:calc(1em +
|
| 7208 |
|
| 7209 |
body, .gradio-container { padding-top:0!important; margin-top:0!important; }
|
| 7210 |
.main { padding-top:0!important; }
|
|
@@ -7219,7 +7190,7 @@ if __name__ == "__main__":
|
|
| 7219 |
border-color:#4A90D9!important;border-width:2.5px!important}
|
| 7220 |
button{border-width:2px!important;border-style:solid!important}
|
| 7221 |
.msg-ai{background:#f5f5f5;margin-right:18%;line-height:1.5;white-space:pre-wrap;}
|
| 7222 |
-
.chat-box{padding-left:
|
| 7223 |
|
| 7224 |
/* Corpus status box styling */
|
| 7225 |
#corpus_status, .corpus-status-box {
|
|
@@ -7231,33 +7202,66 @@ if __name__ == "__main__":
|
|
| 7231 |
}
|
| 7232 |
"""
|
| 7233 |
|
| 7234 |
-
js="""
|
| 7235 |
-
|
| 7236 |
-
|
| 7237 |
-
|
| 7238 |
-
|
| 7239 |
-
|
| 7240 |
-
|
| 7241 |
-
|
| 7242 |
-
|
| 7243 |
-
|
| 7244 |
-
|
| 7245 |
-
|
| 7246 |
-
|
| 7247 |
-
|
| 7248 |
-
|
| 7249 |
-
|
| 7250 |
-
|
| 7251 |
-
|
| 7252 |
-
|
| 7253 |
-
|
| 7254 |
-
|
| 7255 |
-
|
| 7256 |
-
|
| 7257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7258 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7259 |
});
|
| 7260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7261 |
|
| 7262 |
# Initialize LLM clients
|
| 7263 |
initialize_llm_clients()
|
|
@@ -7290,7 +7294,7 @@ if __name__ == "__main__":
|
|
| 7290 |
app.queue(max_size=100, default_concurrency_limit=10) # required for concurrent multi-user support
|
| 7291 |
app.launch(
|
| 7292 |
css=css,
|
| 7293 |
-
|
| 7294 |
server_name="0.0.0.0", # Local only - change to "0.0.0.0" for network access
|
| 7295 |
server_port=int(args.port), # Default 7860
|
| 7296 |
share=False, # Keep this as False for local
|
|
|
|
| 6159 |
# visibility + opacity are delayed 0.7 s before hiding so the user has
|
| 6160 |
# time to move the mouse from the anchor into the popup.
|
| 6161 |
".tt-popup{opacity:0;visibility:hidden;pointer-events:auto;"
|
| 6162 |
+
"position:fixed;z-index:99999;background:#fff;color:#111;"
|
| 6163 |
"border:2px solid #bbb;border-radius:10px;padding:10px 12px;width:max-content;"
|
| 6164 |
"max-width:min(500px,calc(100vw - 40px));box-shadow:0 8px 20px rgba(0,0,0,0.15);font-family:inherit;"
|
| 6165 |
"font-size:0.7em!important;line-height:1.25!important;text-align:left;"
|
| 6166 |
+
"bottom:auto;left:0;top:0;transform:none;"
|
| 6167 |
"transition:opacity 0s 0.15s,visibility 0s 0.15s;}"
|
| 6168 |
|
| 6169 |
# Prevent tooltip from going beyond left edge
|
| 6170 |
+
# ".tt-popup{left:max(10px,min(50%,calc(100% - 10px)));transform:translateX(min(0px,max(-100%,calc(-50% - 10px))));}"
|
| 6171 |
|
| 6172 |
# Show immediately on anchor hover OR when mouse is on the popup itself.
|
| 6173 |
# Both paths are always reachable because pointer-events is never none.
|
| 6174 |
".tt-anchor:hover .tt-popup,.tt-popup:hover{opacity:1;visibility:visible;transition:opacity 0s 0s,visibility 0s 0s;}"
|
| 6175 |
|
| 6176 |
# Position below when near top
|
| 6177 |
+
# ".tt-anchor.near-top .tt-popup{bottom:auto;top:calc(100% + 8px);}"
|
| 6178 |
|
| 6179 |
"""
|
| 6180 |
/* Override Gradio theme variables */
|
|
|
|
| 6262 |
|
| 6263 |
"</style>"
|
| 6264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6265 |
)
|
| 6266 |
h = [css, '<div class="chat-box">']
|
| 6267 |
for m in messages:
|
|
|
|
| 6539 |
|
| 6540 |
|
| 6541 |
# CENTER: conversation
|
| 6542 |
+
with gr.Column(scale=8):
|
| 6543 |
conversation_panel_title = "### 💬 Conversation"
|
| 6544 |
if show_raghl_default:
|
| 6545 |
conversation_panel_title += " | Hover highlighted text to see why it was flagged."
|
|
|
|
| 6562 |
|
| 6563 |
# RIGHT: risk panel
|
| 6564 |
right_col_needed = show_risk_default or show_pii_hl_default or (show_infr_default != 0)
|
| 6565 |
+
with gr.Column(scale=3, visible=right_col_needed) as risk_col:
|
| 6566 |
risk_title = gr.Markdown("### 🛡️ Privacy Risk", visible=False)
|
| 6567 |
risk_html = gr.HTML(create_risk_display(0), visible=False)
|
| 6568 |
analysis_title = gr.Markdown("### 📝 Analysis", visible=False)
|
|
|
|
| 7175 |
color-scheme:light!important}
|
| 7176 |
.gradio-container{background:#fff!important}
|
| 7177 |
.dark .gradio-container{background:#fff!important}
|
| 7178 |
+
.gradio-container,.gradio-container *{font-size:calc(1em + 0px)!important}
|
| 7179 |
|
| 7180 |
body, .gradio-container { padding-top:0!important; margin-top:0!important; }
|
| 7181 |
.main { padding-top:0!important; }
|
|
|
|
| 7190 |
border-color:#4A90D9!important;border-width:2.5px!important}
|
| 7191 |
button{border-width:2px!important;border-style:solid!important}
|
| 7192 |
.msg-ai{background:#f5f5f5;margin-right:18%;line-height:1.5;white-space:pre-wrap;}
|
| 7193 |
+
.chat-box{padding-left: 0px;padding-top: 0px;padding-right: 0px;}
|
| 7194 |
|
| 7195 |
/* Corpus status box styling */
|
| 7196 |
#corpus_status, .corpus-status-box {
|
|
|
|
| 7202 |
}
|
| 7203 |
"""
|
| 7204 |
|
| 7205 |
+
js = """
|
| 7206 |
+
<script>
|
| 7207 |
+
(function() {
|
| 7208 |
+
function attachTooltipListeners() {
|
| 7209 |
+
/* Position popup on mouseenter — viewport-relative (position:fixed) */
|
| 7210 |
+
document.addEventListener('mouseenter', function(e) {
|
| 7211 |
+
var anchor = e.target.closest('.tt-anchor');
|
| 7212 |
+
if (!anchor) return;
|
| 7213 |
+
var rect = anchor.getBoundingClientRect();
|
| 7214 |
+
var nearTop = rect.top < window.innerHeight * 0.3;
|
| 7215 |
+
anchor.querySelectorAll('.tt-popup').forEach(function(p) {
|
| 7216 |
+
var popW = Math.min(500, window.innerWidth - 40);
|
| 7217 |
+
var idealLeft = rect.left + rect.width / 2 - popW / 2; /* centered over anchor */
|
| 7218 |
+
var overflowRight = (idealLeft + popW + 10) - window.innerWidth; /* how many px overflow right edge */
|
| 7219 |
+
var overflowLeft = 10 - idealLeft; /* how many px overflow left edge */
|
| 7220 |
+
var left = idealLeft - Math.max(0, overflowRight) + Math.max(0, overflowLeft);
|
| 7221 |
+
p.style.left = left + 'px';
|
| 7222 |
+
p.style.width = popW + 'px';
|
| 7223 |
+
if (nearTop) {
|
| 7224 |
+
p.style.top = (rect.bottom + 8) + 'px';
|
| 7225 |
+
p.style.transform = 'none';
|
| 7226 |
+
} else {
|
| 7227 |
+
p.style.top = (rect.top - 8) + 'px';
|
| 7228 |
+
p.style.transform = 'translateY(-100%)';
|
| 7229 |
+
}
|
| 7230 |
+
});
|
| 7231 |
+
}, true);
|
| 7232 |
+
|
| 7233 |
+
/* Double-click to pin/unpin */
|
| 7234 |
+
document.addEventListener('dblclick', function(e) {
|
| 7235 |
+
var anchor = e.target.closest('.tt-anchor');
|
| 7236 |
+
if (!anchor) return;
|
| 7237 |
+
var popup = anchor.querySelector('.tt-popup');
|
| 7238 |
+
if (!popup) return;
|
| 7239 |
+
var pinned = anchor.classList.toggle('tt-pin-active');
|
| 7240 |
+
popup.classList.toggle('tt-pinned', pinned);
|
| 7241 |
+
e.preventDefault();
|
| 7242 |
});
|
| 7243 |
+
|
| 7244 |
+
/* Click outside to dismiss pinned */
|
| 7245 |
+
document.addEventListener('click', function(e) {
|
| 7246 |
+
if (!e.target.closest('.tt-pin-active')) {
|
| 7247 |
+
document.querySelectorAll('.tt-anchor.tt-pin-active').forEach(function(a) {
|
| 7248 |
+
a.classList.remove('tt-pin-active');
|
| 7249 |
+
a.querySelectorAll('.tt-popup').forEach(function(p) { p.classList.remove('tt-pinned'); });
|
| 7250 |
+
});
|
| 7251 |
+
}
|
| 7252 |
});
|
| 7253 |
+
}
|
| 7254 |
+
|
| 7255 |
+
/* Gradio renders dynamically — poll until the app root exists, then attach */
|
| 7256 |
+
var poll = setInterval(function() {
|
| 7257 |
+
if (document.querySelector('.gradio-container')) {
|
| 7258 |
+
clearInterval(poll);
|
| 7259 |
+
attachTooltipListeners();
|
| 7260 |
+
}
|
| 7261 |
+
}, 100);
|
| 7262 |
+
})();
|
| 7263 |
+
</script>
|
| 7264 |
+
"""
|
| 7265 |
|
| 7266 |
# Initialize LLM clients
|
| 7267 |
initialize_llm_clients()
|
|
|
|
| 7294 |
app.queue(max_size=100, default_concurrency_limit=10) # required for concurrent multi-user support
|
| 7295 |
app.launch(
|
| 7296 |
css=css,
|
| 7297 |
+
head=js,
|
| 7298 |
server_name="0.0.0.0", # Local only - change to "0.0.0.0" for network access
|
| 7299 |
server_port=int(args.port), # Default 7860
|
| 7300 |
share=False, # Keep this as False for local
|