Update app.py
Browse files
app.py
CHANGED
|
@@ -29,19 +29,46 @@ def analyze_text(text, top_k):
|
|
| 29 |
css = """<style>
|
| 30 |
.tc{display:flex;flex-wrap:wrap;gap:5px;padding:20px;line-height:2.4;font-family:'Segoe UI',sans-serif}
|
| 31 |
.tw{position:relative;display:inline-block}
|
| 32 |
-
.tk{padding:4px 7px;border-radius:6px;cursor:
|
| 33 |
.tw:hover .tk{transform:translateY(-2px);box-shadow:0 4px 14px rgba(0,0,0,.18);border-color:#999}
|
| 34 |
.tt{display:none;position:absolute;bottom:calc(100% + 8px);left:50%;transform:translateX(-50%);
|
| 35 |
background:#1a1a2e;color:#eee;padding:14px;border-radius:12px;font-size:13px;z-index:9999;
|
| 36 |
box-shadow:0 10px 30px rgba(0,0,0,.35);min-width:220px;max-height:350px;overflow-y:auto}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
.tw:hover .tt{display:block}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
.th{font-weight:700;font-size:14px;color:#7fdbca;border-bottom:1px solid #333;padding-bottom:6px;margin-bottom:6px}
|
| 39 |
.tp{color:#ffd700;margin-bottom:8px}
|
| 40 |
.at{color:#ff79c6;font-size:10px;text-transform:uppercase;letter-spacing:1px;margin-bottom:4px}
|
| 41 |
.aw{display:flex;justify-content:space-between;padding:2px 0;font-size:12px}
|
| 42 |
.aw .w{color:#c3cee3}.aw .p{color:#666;margin-left:14px}
|
| 43 |
.hi{font-weight:700;color:#7fdbca!important}
|
| 44 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
parts = [css, '<div class="tc">']
|
| 47 |
for i in range(len(tokens)):
|
|
@@ -79,7 +106,7 @@ box-shadow:0 10px 30px rgba(0,0,0,.35);min-width:220px;max-height:350px;overflow
|
|
| 79 |
|
| 80 |
|
| 81 |
with gr.Blocks(theme=gr.themes.Soft(), css="footer{display:none!important}.main{max-width:960px;margin:auto}") as demo:
|
| 82 |
-
gr.Markdown("# 🔍 Token Probability Explorer\nPaste text, hover
|
| 83 |
with gr.Row():
|
| 84 |
text_input = gr.Textbox(label="Input Text", placeholder="Paste your text here…", lines=5, scale=4)
|
| 85 |
top_k_input = gr.Number(label="# Alternatives", value=10, minimum=1, maximum=200, step=1, scale=1)
|
|
|
|
| 29 |
css = """<style>
|
| 30 |
.tc{display:flex;flex-wrap:wrap;gap:5px;padding:20px;line-height:2.4;font-family:'Segoe UI',sans-serif}
|
| 31 |
.tw{position:relative;display:inline-block}
|
| 32 |
+
.tk{padding:4px 7px;border-radius:6px;cursor:pointer;font-size:15px;transition:.2s;border:1px solid transparent;user-select:none}
|
| 33 |
.tw:hover .tk{transform:translateY(-2px);box-shadow:0 4px 14px rgba(0,0,0,.18);border-color:#999}
|
| 34 |
.tt{display:none;position:absolute;bottom:calc(100% + 8px);left:50%;transform:translateX(-50%);
|
| 35 |
background:#1a1a2e;color:#eee;padding:14px;border-radius:12px;font-size:13px;z-index:9999;
|
| 36 |
box-shadow:0 10px 30px rgba(0,0,0,.35);min-width:220px;max-height:350px;overflow-y:auto}
|
| 37 |
+
|
| 38 |
+
/* Bridge the gap between token and tooltip with a pseudo-element */
|
| 39 |
+
.tt::after{content:'';position:absolute;top:100%;left:0;width:100%;height:12px}
|
| 40 |
+
|
| 41 |
+
/* Show on hover */
|
| 42 |
.tw:hover .tt{display:block}
|
| 43 |
+
|
| 44 |
+
/* Show when pinned via click */
|
| 45 |
+
.tw.pinned .tt{display:block}
|
| 46 |
+
.tw.pinned .tk{transform:translateY(-2px);box-shadow:0 4px 14px rgba(0,0,0,.18);border-color:#999;outline:2px solid #7fdbca}
|
| 47 |
+
|
| 48 |
.th{font-weight:700;font-size:14px;color:#7fdbca;border-bottom:1px solid #333;padding-bottom:6px;margin-bottom:6px}
|
| 49 |
.tp{color:#ffd700;margin-bottom:8px}
|
| 50 |
.at{color:#ff79c6;font-size:10px;text-transform:uppercase;letter-spacing:1px;margin-bottom:4px}
|
| 51 |
.aw{display:flex;justify-content:space-between;padding:2px 0;font-size:12px}
|
| 52 |
.aw .w{color:#c3cee3}.aw .p{color:#666;margin-left:14px}
|
| 53 |
.hi{font-weight:700;color:#7fdbca!important}
|
| 54 |
+
</style>
|
| 55 |
+
<script>
|
| 56 |
+
document.addEventListener('click', function(e) {
|
| 57 |
+
const tk = e.target.closest('.tk');
|
| 58 |
+
const tw = tk ? tk.closest('.tw') : null;
|
| 59 |
+
// If clicked a token, toggle its pin
|
| 60 |
+
if (tw) {
|
| 61 |
+
const wasPinned = tw.classList.contains('pinned');
|
| 62 |
+
// Unpin all others
|
| 63 |
+
document.querySelectorAll('.tw.pinned').forEach(el => el.classList.remove('pinned'));
|
| 64 |
+
// Toggle this one
|
| 65 |
+
if (!wasPinned) tw.classList.add('pinned');
|
| 66 |
+
} else if (!e.target.closest('.tt')) {
|
| 67 |
+
// Clicked outside any token or tooltip — unpin all
|
| 68 |
+
document.querySelectorAll('.tw.pinned').forEach(el => el.classList.remove('pinned'));
|
| 69 |
+
}
|
| 70 |
+
});
|
| 71 |
+
</script>"""
|
| 72 |
|
| 73 |
parts = [css, '<div class="tc">']
|
| 74 |
for i in range(len(tokens)):
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
with gr.Blocks(theme=gr.themes.Soft(), css="footer{display:none!important}.main{max-width:960px;margin:auto}") as demo:
|
| 109 |
+
gr.Markdown("# 🔍 Token Probability Explorer\nPaste text, **hover** to preview or **click** a token to pin its tooltip open. Click elsewhere to dismiss.")
|
| 110 |
with gr.Row():
|
| 111 |
text_input = gr.Textbox(label="Input Text", placeholder="Paste your text here…", lines=5, scale=4)
|
| 112 |
top_k_input = gr.Number(label="# Alternatives", value=10, minimum=1, maximum=200, step=1, scale=1)
|