Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +90 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,92 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 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 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# --- CONFIG ---
|
| 8 |
+
st.set_page_config(layout="wide", page_title="Semantic-Drive Explorer", page_icon="🚗")
|
| 9 |
+
DATA_FILE = "demo_data.jsonl"
|
| 10 |
+
|
| 11 |
+
# --- SIDEBAR ---
|
| 12 |
+
st.sidebar.title("🚗 Semantic-Drive")
|
| 13 |
+
st.sidebar.markdown("**Mining Long-Tail Edge Cases with Neuro-Symbolic VLMs**")
|
| 14 |
+
st.sidebar.info("This demo showcases scenarios retrieved from NuScenes using a local Llama-3/Qwen pipeline running on consumer hardware.")
|
| 15 |
+
|
| 16 |
+
# --- LOAD DATA ---
|
| 17 |
+
@st.cache_data
|
| 18 |
+
def load_data():
|
| 19 |
+
if not os.path.exists(DATA_FILE):
|
| 20 |
+
return pd.DataFrame()
|
| 21 |
+
data = []
|
| 22 |
+
with open(DATA_FILE, 'r') as f:
|
| 23 |
+
for line in f:
|
| 24 |
+
data.append(json.loads(line))
|
| 25 |
+
return pd.DataFrame(data)
|
| 26 |
+
|
| 27 |
+
df = load_data()
|
| 28 |
+
|
| 29 |
+
if df.empty:
|
| 30 |
+
st.error("No data found. Please upload demo_data.jsonl")
|
| 31 |
+
st.stop()
|
| 32 |
+
|
| 33 |
+
# --- FILTERS ---
|
| 34 |
+
st.sidebar.header("🔍 Search Filters")
|
| 35 |
+
|
| 36 |
+
# 1. Filter by Tags
|
| 37 |
+
all_tags = set()
|
| 38 |
+
for tags in df['wod_e2e_tags']:
|
| 39 |
+
all_tags.update(tags)
|
| 40 |
+
|
| 41 |
+
selected_tags = st.sidebar.multiselect("WOD-E2E Tags", sorted(list(all_tags)))
|
| 42 |
+
|
| 43 |
+
# 2. Filter by Risk
|
| 44 |
+
min_risk = st.sidebar.slider("Minimum Risk Score", 0, 10, 0)
|
| 45 |
+
|
| 46 |
+
# Apply Filters
|
| 47 |
+
filtered_df = df.copy()
|
| 48 |
+
if selected_tags:
|
| 49 |
+
filtered_df = filtered_df[filtered_df['wod_e2e_tags'].apply(lambda x: any(t in x for t in selected_tags))]
|
| 50 |
+
filtered_df = filtered_df[filtered_df.apply(lambda x: x['scenario_criticality']['risk_score'] >= min_risk, axis=1)]
|
| 51 |
+
|
| 52 |
+
st.sidebar.markdown(f"**Found:** {len(filtered_df)} / {len(df)} scenarios")
|
| 53 |
+
|
| 54 |
+
# --- MAIN FEED ---
|
| 55 |
+
st.title("Scenario Database")
|
| 56 |
+
|
| 57 |
+
# Display as a feed of cards
|
| 58 |
+
for idx, row in filtered_df.iterrows():
|
| 59 |
+
with st.container():
|
| 60 |
+
c1, c2 = st.columns([1, 2])
|
| 61 |
+
|
| 62 |
+
with c1:
|
| 63 |
+
# Load Image
|
| 64 |
+
img_path = row.get("web_image_path", "")
|
| 65 |
+
if os.path.exists(img_path):
|
| 66 |
+
img = Image.open(img_path)
|
| 67 |
+
st.image(img, use_container_width=True, caption=f"Token: {row['token'][:8]}...")
|
| 68 |
+
else:
|
| 69 |
+
st.warning("Image not available in demo pack")
|
| 70 |
|
| 71 |
+
with c2:
|
| 72 |
+
# Header
|
| 73 |
+
tags = row['wod_e2e_tags']
|
| 74 |
+
risk = row['scenario_criticality']['risk_score']
|
| 75 |
+
|
| 76 |
+
# Badge Logic
|
| 77 |
+
risk_color = "red" if risk >= 7 else "orange" if risk >= 4 else "green"
|
| 78 |
+
st.markdown(f"### :{risk_color}[Risk {risk}/10] {' '.join([f'`{t}`' for t in tags])}")
|
| 79 |
+
|
| 80 |
+
# Description
|
| 81 |
+
st.info(row['description'])
|
| 82 |
+
|
| 83 |
+
# Details Expander
|
| 84 |
+
with st.expander("🧬 View Scenario DNA (JSON)"):
|
| 85 |
+
st.json({
|
| 86 |
+
"ODD": row['odd_attributes'],
|
| 87 |
+
"Topology": row['road_topology'],
|
| 88 |
+
"Agents": row['key_interacting_agents'],
|
| 89 |
+
"Reasoning": row.get('judge_log', [])
|
| 90 |
+
})
|
| 91 |
+
|
| 92 |
+
st.divider()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|