davidlf-hp commited on
Commit
8f895ab
·
verified ·
1 Parent(s): 69888c2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +66 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,68 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
 
 
 
 
 
 
4
  import streamlit as st
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Streamlit app to display the NPU Arabic leaderboard."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from datetime import datetime
7
+ from pathlib import Path
8
+ from typing import List, Sequence
9
+
10
  import streamlit as st
11
 
12
+ _DATA_PATH = Path("leaderboard.json")
13
+ _COLUMNS: Sequence[str] = (
14
+ "model_name",
15
+ "avg_tps",
16
+ "iwslt2017-en-ar_sacrebleu",
17
+ "mlqa_ar_ar_f1",
18
+ "xquad_ar_f1",
19
+ "timestamp",
20
+ )
21
+
22
+
23
+ def _load_rows() -> List[dict]:
24
+ if not _DATA_PATH.exists():
25
+ return []
26
+ try:
27
+ raw = json.loads(_DATA_PATH.read_text(encoding="utf-8"))
28
+ except json.JSONDecodeError:
29
+ return []
30
+
31
+ if isinstance(raw, dict):
32
+ data = [raw]
33
+ elif isinstance(raw, list):
34
+ data = [item for item in raw if isinstance(item, dict)]
35
+ else:
36
+ data = []
37
+
38
+ # Filter to desired columns and sort newest-first.
39
+ filtered: List[dict] = []
40
+ for row in data:
41
+ compact = {key: row.get(key) for key in _COLUMNS}
42
+ filtered.append(compact)
43
+
44
+ def _sort_key(item: dict) -> tuple:
45
+ stamp = item.get("timestamp")
46
+ try:
47
+ return (datetime.fromisoformat(str(stamp)),)
48
+ except Exception:
49
+ return (datetime.min,)
50
+
51
+ filtered.sort(key=_sort_key, reverse=True)
52
+ return filtered
53
+
54
+
55
+ st.set_page_config(page_title="Intel NPU Arabic Leaderboard", layout="wide")
56
+ st.title("Intel® NPU Arabic Leaderboard")
57
+
58
+ rows = _load_rows()
59
+ if not rows:
60
+ st.info("No evaluations uploaded yet. Trigger a run to populate the leaderboard.")
61
+ else:
62
+ st.write(
63
+ "Latest evaluation per model. Add new results by emailing the evaluation endpoint "
64
+ "or running the CLI with the Hugging Face publishing flags."
65
+ )
66
+ st.dataframe(rows, column_config={col: st.column_config.Column(col) for col in _COLUMNS})
67
+
68
+ st.caption("Data auto-synced from leaderboard.json produced by the evaluation pipeline.")