Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +21 -15
src/streamlit_app.py
CHANGED
|
@@ -69,7 +69,7 @@ def check_target_single_token(tokenizer, target_str: str) -> tuple[bool, list[in
|
|
| 69 |
|
| 70 |
|
| 71 |
def _is_comma_delimited_numbers(s: str) -> bool:
|
| 72 |
-
"""Check if string is comma-delimited integers."""
|
| 73 |
try:
|
| 74 |
parts = [x.strip() for x in s.split(",") if x.strip()]
|
| 75 |
return len(parts) > 0 and all(p.lstrip("-").isdigit() for p in parts)
|
|
@@ -435,25 +435,29 @@ def main():
|
|
| 435 |
model_name = MODEL_MAP[model_choice]
|
| 436 |
|
| 437 |
attribution_type = st.radio(
|
| 438 |
-
"
|
| 439 |
options=["Semantic Scope", "Temperature Scope"],
|
| 440 |
index=0,
|
| 441 |
horizontal=True,
|
| 442 |
key="attribution_type",
|
| 443 |
-
help="Semantic Scope: attribute toward a target token. Temperature Scope: use hidden-state norm.",
|
| 444 |
)
|
| 445 |
mode = "Semantic" if attribution_type == "Semantic Scope" else "Temperature"
|
| 446 |
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
if is_comma_delimited:
|
| 459 |
default_text = (
|
|
@@ -469,13 +473,15 @@ def main():
|
|
| 469 |
"French: Cet article porte sur l'attribution causale, que nous appelons lentille jacobienne. English: This is a paper on causal attribution, and we call it Jacobian"
|
| 470 |
)
|
| 471 |
|
|
|
|
|
|
|
| 472 |
text_input = st.text_area(
|
| 473 |
"Input text",
|
| 474 |
value=default_text,
|
| 475 |
height=120,
|
| 476 |
key=f"text_input_{mode}_{input_type}",
|
| 477 |
-
placeholder=
|
| 478 |
-
help=
|
| 479 |
)
|
| 480 |
|
| 481 |
target_str = None
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
def _is_comma_delimited_numbers(s: str) -> bool:
|
| 72 |
+
"""Check if string is comma-delimited, two-digit integers."""
|
| 73 |
try:
|
| 74 |
parts = [x.strip() for x in s.split(",") if x.strip()]
|
| 75 |
return len(parts) > 0 and all(p.lstrip("-").isdigit() for p in parts)
|
|
|
|
| 435 |
model_name = MODEL_MAP[model_choice]
|
| 436 |
|
| 437 |
attribution_type = st.radio(
|
| 438 |
+
"Scope type",
|
| 439 |
options=["Semantic Scope", "Temperature Scope"],
|
| 440 |
index=0,
|
| 441 |
horizontal=True,
|
| 442 |
key="attribution_type",
|
| 443 |
+
# help="Semantic Scope: attribute toward a target token. Temperature Scope: use hidden-state norm.",
|
| 444 |
)
|
| 445 |
mode = "Semantic" if attribution_type == "Semantic Scope" else "Temperature"
|
| 446 |
|
| 447 |
+
if mode == "Semantic":
|
| 448 |
+
input_type = "text"
|
| 449 |
+
is_comma_delimited = False
|
| 450 |
+
else:
|
| 451 |
+
input_type_default = "comma_delimited"
|
| 452 |
+
input_type = st.radio(
|
| 453 |
+
"Input type",
|
| 454 |
+
options=["text", "comma-delimited numbers"],
|
| 455 |
+
index=0 if input_type_default == "text" else 1,
|
| 456 |
+
horizontal=True,
|
| 457 |
+
key=f"input_type_{mode}",
|
| 458 |
+
help="Text: natural language. Comma-delimited numbers: time-series style. Delimiters are skipped for attribution.",
|
| 459 |
+
)
|
| 460 |
+
is_comma_delimited = input_type == "comma-delimited numbers"
|
| 461 |
|
| 462 |
if is_comma_delimited:
|
| 463 |
default_text = (
|
|
|
|
| 473 |
"French: Cet article porte sur l'attribution causale, que nous appelons lentille jacobienne. English: This is a paper on causal attribution, and we call it Jacobian"
|
| 474 |
)
|
| 475 |
|
| 476 |
+
text_placeholder = "Input text" if mode == "Semantic" else "Input text or comma-delimited numbers"
|
| 477 |
+
text_help = "Natural language input." if mode == "Semantic" else "Text or comma-separated numbers. Delimiters are skipped for comma-delimited."
|
| 478 |
text_input = st.text_area(
|
| 479 |
"Input text",
|
| 480 |
value=default_text,
|
| 481 |
height=120,
|
| 482 |
key=f"text_input_{mode}_{input_type}",
|
| 483 |
+
placeholder=text_placeholder,
|
| 484 |
+
help=text_help,
|
| 485 |
)
|
| 486 |
|
| 487 |
target_str = None
|