Spaces:
Running
Running
Yoad
commited on
Commit
·
1165618
1
Parent(s):
7b3ae60
Add manual Entry mode
Browse files- src/app.py +30 -21
- src/manual_evlaution.py +37 -0
- src/utils.py +30 -0
src/app.py
CHANGED
|
@@ -9,10 +9,12 @@ import requests
|
|
| 9 |
import streamlit as st
|
| 10 |
from huggingface_hub import HfFileSystem
|
| 11 |
|
|
|
|
| 12 |
from st_fixed_container import st_fixed_container
|
|
|
|
| 13 |
from visual_eval.evaluator import HebrewTextNormalizer
|
| 14 |
from visual_eval.visualization import render_visualize_jiwer_result_html
|
| 15 |
-
from
|
| 16 |
|
| 17 |
HF_API_TOKEN = None
|
| 18 |
try:
|
|
@@ -35,6 +37,8 @@ if "audio_cache" not in st.session_state:
|
|
| 35 |
|
| 36 |
if "audio_preview_active" not in st.session_state:
|
| 37 |
st.session_state.audio_preview_active = {}
|
|
|
|
|
|
|
| 38 |
|
| 39 |
if "uploaded_file" not in st.session_state:
|
| 40 |
st.session_state.results_file = None
|
|
@@ -85,7 +89,7 @@ def on_file_upload():
|
|
| 85 |
st.session_state.results_file = None
|
| 86 |
|
| 87 |
|
| 88 |
-
def
|
| 89 |
if "lb_result_file" in st.query_params:
|
| 90 |
st.query_params.pop("lb_result_file")
|
| 91 |
st.session_state.consumed_query_lb_file = None
|
|
@@ -140,19 +144,6 @@ def read_results_csv(uploaded_file):
|
|
| 140 |
results_df = pd.read_csv(uploaded_file)
|
| 141 |
return results_df
|
| 142 |
|
| 143 |
-
|
| 144 |
-
def display_rtl(html):
|
| 145 |
-
"""Render an RTL container with the provided HTML string"""
|
| 146 |
-
st.markdown(
|
| 147 |
-
f"""
|
| 148 |
-
<div dir="rtl" lang="he">
|
| 149 |
-
{html}
|
| 150 |
-
</div>
|
| 151 |
-
""",
|
| 152 |
-
unsafe_allow_html=True,
|
| 153 |
-
)
|
| 154 |
-
|
| 155 |
-
|
| 156 |
@st.cache_data
|
| 157 |
def calculate_final_metrics(uploaded_file, _df):
|
| 158 |
"""Calculate final metrics for all entries
|
|
@@ -307,6 +298,9 @@ def main():
|
|
| 307 |
page_title="ASR Evaluation Visualizer", page_icon="🎤", layout="wide"
|
| 308 |
)
|
| 309 |
|
|
|
|
|
|
|
|
|
|
| 310 |
# Check for URL parameter for preloading leaderboard results
|
| 311 |
lb_result_file_param = st.query_params.get("lb_result_file")
|
| 312 |
if (
|
|
@@ -332,22 +326,32 @@ def main():
|
|
| 332 |
uploaded_file = st.file_uploader(
|
| 333 |
"Upload evaluation results CSV",
|
| 334 |
type=["csv"],
|
| 335 |
-
on_change=
|
| 336 |
key="uploaded_file",
|
| 337 |
)
|
| 338 |
|
| 339 |
if st.session_state.consumed_query_lb_file is not None:
|
| 340 |
-
st.
|
| 341 |
-
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
|
| 344 |
if uploaded_file is not None:
|
| 345 |
st.session_state.results_file = uploaded_file
|
| 346 |
|
| 347 |
-
if
|
| 348 |
st.write("Or:")
|
| 349 |
if st.button("Choose from leaderboard"):
|
| 350 |
choose_input_file_from_leaderboard()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
if st.session_state.results_file is not None:
|
| 353 |
uploaded_file = st.session_state.results_file
|
|
@@ -355,7 +359,6 @@ def main():
|
|
| 355 |
try:
|
| 356 |
eval_results = read_results_csv(uploaded_file)
|
| 357 |
st.session_state.total_entry_count = len(eval_results)
|
| 358 |
-
st.success("File uploaded successfully!")
|
| 359 |
|
| 360 |
with st.sidebar:
|
| 361 |
# Toggle for calculating total metrics
|
|
@@ -525,6 +528,12 @@ def main():
|
|
| 525 |
|
| 526 |
except Exception as e:
|
| 527 |
st.error(f"Error processing file: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
else:
|
| 529 |
st.info(
|
| 530 |
"Please upload an evaluation results CSV file to visualize the results."
|
|
|
|
| 9 |
import streamlit as st
|
| 10 |
from huggingface_hub import HfFileSystem
|
| 11 |
|
| 12 |
+
from manual_evlaution import render_manual_eval
|
| 13 |
from st_fixed_container import st_fixed_container
|
| 14 |
+
from substitutions_visualizer import visualize_substitutions
|
| 15 |
from visual_eval.evaluator import HebrewTextNormalizer
|
| 16 |
from visual_eval.visualization import render_visualize_jiwer_result_html
|
| 17 |
+
from utils import display_rtl, ltr_tag
|
| 18 |
|
| 19 |
HF_API_TOKEN = None
|
| 20 |
try:
|
|
|
|
| 37 |
|
| 38 |
if "audio_preview_active" not in st.session_state:
|
| 39 |
st.session_state.audio_preview_active = {}
|
| 40 |
+
if "manual_mode" not in st.session_state:
|
| 41 |
+
st.session_state.manual_mode = False
|
| 42 |
|
| 43 |
if "uploaded_file" not in st.session_state:
|
| 44 |
st.session_state.results_file = None
|
|
|
|
| 89 |
st.session_state.results_file = None
|
| 90 |
|
| 91 |
|
| 92 |
+
def reset_upload_state():
|
| 93 |
if "lb_result_file" in st.query_params:
|
| 94 |
st.query_params.pop("lb_result_file")
|
| 95 |
st.session_state.consumed_query_lb_file = None
|
|
|
|
| 144 |
results_df = pd.read_csv(uploaded_file)
|
| 145 |
return results_df
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
@st.cache_data
|
| 148 |
def calculate_final_metrics(uploaded_file, _df):
|
| 149 |
"""Calculate final metrics for all entries
|
|
|
|
| 298 |
page_title="ASR Evaluation Visualizer", page_icon="🎤", layout="wide"
|
| 299 |
)
|
| 300 |
|
| 301 |
+
# RTL some tags
|
| 302 |
+
ltr_tag("textarea")
|
| 303 |
+
|
| 304 |
# Check for URL parameter for preloading leaderboard results
|
| 305 |
lb_result_file_param = st.query_params.get("lb_result_file")
|
| 306 |
if (
|
|
|
|
| 326 |
uploaded_file = st.file_uploader(
|
| 327 |
"Upload evaluation results CSV",
|
| 328 |
type=["csv"],
|
| 329 |
+
on_change=reset_upload_state(),
|
| 330 |
key="uploaded_file",
|
| 331 |
)
|
| 332 |
|
| 333 |
if st.session_state.consumed_query_lb_file is not None:
|
| 334 |
+
clear_col1, clear_col2 = st.columns([10, 1], gap="large")
|
| 335 |
+
with clear_col1:
|
| 336 |
+
st.info(
|
| 337 |
+
f"Loaded: {st.session_state.consumed_query_lb_file or uploaded_file}"
|
| 338 |
+
)
|
| 339 |
+
with clear_col2:
|
| 340 |
+
if st.button("Unload"):
|
| 341 |
+
reset_upload_state()
|
| 342 |
+
st.rerun()
|
| 343 |
|
| 344 |
if uploaded_file is not None:
|
| 345 |
st.session_state.results_file = uploaded_file
|
| 346 |
|
| 347 |
+
if st.session_state.results_file is None:
|
| 348 |
st.write("Or:")
|
| 349 |
if st.button("Choose from leaderboard"):
|
| 350 |
choose_input_file_from_leaderboard()
|
| 351 |
+
if st.button("Enter Manually"):
|
| 352 |
+
st.session_state.manual_mode = True
|
| 353 |
+
reset_upload_state()
|
| 354 |
+
st.rerun()
|
| 355 |
|
| 356 |
if st.session_state.results_file is not None:
|
| 357 |
uploaded_file = st.session_state.results_file
|
|
|
|
| 359 |
try:
|
| 360 |
eval_results = read_results_csv(uploaded_file)
|
| 361 |
st.session_state.total_entry_count = len(eval_results)
|
|
|
|
| 362 |
|
| 363 |
with st.sidebar:
|
| 364 |
# Toggle for calculating total metrics
|
|
|
|
| 528 |
|
| 529 |
except Exception as e:
|
| 530 |
st.error(f"Error processing file: {str(e)}")
|
| 531 |
+
elif st.session_state.manual_mode:
|
| 532 |
+
st.info(
|
| 533 |
+
"Please enter the evaluation results CSV file to visualize the results."
|
| 534 |
+
)
|
| 535 |
+
render_manual_eval()
|
| 536 |
+
|
| 537 |
else:
|
| 538 |
st.info(
|
| 539 |
"Please upload an evaluation results CSV file to visualize the results."
|
src/manual_evlaution.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
from visual_eval.evaluator import HebrewTextNormalizer
|
| 4 |
+
from visual_eval.visualization import render_visualize_jiwer_result_html
|
| 5 |
+
from substitutions_visualizer import visualize_substitutions
|
| 6 |
+
from utils import display_rtl
|
| 7 |
+
|
| 8 |
+
norm = HebrewTextNormalizer()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@st.fragment
|
| 12 |
+
def manual_eval_viz(ref, hyp):
|
| 13 |
+
show_subs = st.toggle("Show Substitutions", value=False)
|
| 14 |
+
norm_texts = st.toggle("Normalize Texts", value=True)
|
| 15 |
+
if norm_texts:
|
| 16 |
+
ref = norm(ref)
|
| 17 |
+
hyp = norm(hyp)
|
| 18 |
+
html = render_visualize_jiwer_result_html(ref, hyp)
|
| 19 |
+
display_rtl(html)
|
| 20 |
+
if show_subs:
|
| 21 |
+
visualize_substitutions(ref, hyp)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def render_manual_eval():
|
| 25 |
+
col_ref, col_hyp = st.columns([1, 1], gap="small")
|
| 26 |
+
ref = None
|
| 27 |
+
hyp = None
|
| 28 |
+
with col_ref:
|
| 29 |
+
ref = st.text_area("Reference Text", height=100)
|
| 30 |
+
with col_hyp:
|
| 31 |
+
hyp = st.text_area("Hypothesis Text", height=100)
|
| 32 |
+
|
| 33 |
+
if st.button("Visualize"):
|
| 34 |
+
if hyp and ref:
|
| 35 |
+
manual_eval_viz(ref, hyp)
|
| 36 |
+
else:
|
| 37 |
+
st.error("Please enter both reference and hypothesis text.")
|
src/utils.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def ltr_tag(tag):
|
| 5 |
+
style = """
|
| 6 |
+
{
|
| 7 |
+
unicode-bidi:bidi-override;
|
| 8 |
+
direction: RTL;
|
| 9 |
+
}
|
| 10 |
+
"""
|
| 11 |
+
st.markdown(
|
| 12 |
+
f"""
|
| 13 |
+
<style>
|
| 14 |
+
{tag}, .rtl {style}
|
| 15 |
+
</style>
|
| 16 |
+
""",
|
| 17 |
+
unsafe_allow_html=True,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def display_rtl(html):
|
| 22 |
+
"""Render an RTL container with the provided HTML string"""
|
| 23 |
+
st.markdown(
|
| 24 |
+
f"""
|
| 25 |
+
<div dir="rtl" lang="he">
|
| 26 |
+
{html}
|
| 27 |
+
</div>
|
| 28 |
+
""",
|
| 29 |
+
unsafe_allow_html=True,
|
| 30 |
+
)
|