Spaces:
Sleeping
Sleeping
esemsc-am4224 commited on
Commit ·
ec03603
1
Parent(s): 277590a
feat: improved agentbase platform performance and layout
Browse files- interface.py +73 -74
interface.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
AgentBase Visualisation
|
| 3 |
|
| 4 |
Author: Arastun Mammadli
|
| 5 |
Date: [Current Date]
|
|
@@ -15,51 +15,51 @@ from retrieval.models.sentence_bert import DenseRetriever
|
|
| 15 |
from retrieval.utils import load_queries
|
| 16 |
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
Simple keyword-based boolean filter across specified columns.
|
| 21 |
"""
|
| 22 |
-
if not query: return df
|
| 23 |
-
|
| 24 |
mask = df[columns].astype(str).apply(
|
| 25 |
lambda col: col.str.contains(query, case=False, na=False)
|
| 26 |
).any(axis=1)
|
| 27 |
-
filtered_df = df[mask].head(top_k)
|
| 28 |
filtered_df["scores"] = 1
|
| 29 |
return filtered_df
|
| 30 |
|
|
|
|
| 31 |
class AgentBaseUI:
|
| 32 |
"""
|
| 33 |
AgentBase Streamlit-based UI Components.
|
| 34 |
"""
|
| 35 |
-
|
| 36 |
def __init__(self, agentbase_path, platforms_path):
|
| 37 |
-
self.agents_df =
|
| 38 |
-
self.agents_df['scores'] = 0.0
|
| 39 |
self.platforms_df = pd.read_csv(platforms_path)
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
self.retrieval_models = ["bge-large-en-v1.5", "bm25", "keyword"]
|
| 43 |
self.selected_model = "bge-large-en-v1.5"
|
| 44 |
self.indexing_configs = ["v1", "naive"]
|
| 45 |
-
self.indexing_config = "v1"
|
| 46 |
-
|
| 47 |
-
self.visible_configs = ["indexing1", "indexing2"]
|
| 48 |
-
self.visible_configs_to_indexing = {
|
| 49 |
-
"indexing1": "v1",
|
| 50 |
-
"indexing2": "naive"
|
| 51 |
-
}
|
| 52 |
|
| 53 |
-
|
| 54 |
-
self.bges = {}
|
| 55 |
-
for idx_config in self.indexing_configs:
|
| 56 |
-
self.bm25s[idx_config] = BM25Retriever(agentbase_path, index_config=idx_config)
|
| 57 |
-
self.bges[idx_config] = DenseRetriever("BAAI/bge-large-en-v1.5", agentbase_path, index_config=idx_config)
|
| 58 |
-
|
| 59 |
-
def show_header(self):
|
| 60 |
st.set_page_config(page_title="AgentBase", layout="wide")
|
| 61 |
st.title("AgentBase Platform Demo")
|
| 62 |
st.write("A Large-Scale Agent Collection for Automated Agent Recommendation.")
|
|
|
|
| 63 |
st.subheader("🔍 Retrieval")
|
| 64 |
if "query" not in st.session_state:
|
| 65 |
st.session_state.query = ""
|
|
@@ -71,45 +71,49 @@ class AgentBaseUI:
|
|
| 71 |
st.session_state.query = suggestion
|
| 72 |
|
| 73 |
col1, col2, col3 = st.columns([4, 1, 1])
|
| 74 |
-
with col1:
|
| 75 |
-
st.
|
| 76 |
with col2:
|
| 77 |
self.selected_model = st.selectbox("", self.retrieval_models, index=0)
|
| 78 |
with col3:
|
| 79 |
-
self.indexing_config = st.selectbox("", self.
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
if len(filtered_df) > 0:
|
| 88 |
st.write(f"Showing {top_k} of {len(self.agents_df)} agents")
|
| 89 |
-
#
|
| 90 |
-
agent_config = {
|
| 91 |
"agent_url": st.column_config.LinkColumn("agent_url", display_text="Visit →"),
|
| 92 |
"agent_description": st.column_config.TextColumn("agent_description", width="large"),
|
| 93 |
"agent_accessibility": st.column_config.TextColumn("agent_accessibility", width="small"),
|
| 94 |
}
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
)
|
| 104 |
-
else:
|
| 105 |
-
key_columns = ['agent_name', 'platform_name', 'agent_description', 'agent_url', 'scores']
|
| 106 |
-
if (filtered_df['scores'] == 0).all(): key_columns.remove("scores")
|
| 107 |
-
st.dataframe(
|
| 108 |
-
filtered_df[key_columns].head(top_k),
|
| 109 |
-
column_config=agent_config,
|
| 110 |
-
use_container_width=True,
|
| 111 |
-
hide_index=True
|
| 112 |
-
)
|
| 113 |
else:
|
| 114 |
st.info("No agents match your search.")
|
| 115 |
|
|
@@ -119,11 +123,11 @@ class AgentBaseUI:
|
|
| 119 |
Default maximum top_k of 100
|
| 120 |
"""
|
| 121 |
if self.selected_model == 'keyword':
|
| 122 |
-
return keyword_filter(
|
| 123 |
elif self.selected_model == 'bm25':
|
| 124 |
-
res = self.bm25s[self.
|
| 125 |
elif self.selected_model == 'bge-large-en-v1.5':
|
| 126 |
-
res = self.bges[self.
|
| 127 |
else:
|
| 128 |
raise ValueError(f"Selected model must be one of {self.retrieval_models}")
|
| 129 |
|
|
@@ -134,29 +138,24 @@ class AgentBaseUI:
|
|
| 134 |
score = dict(res).get(row['agent_id'], 0)
|
| 135 |
filtered_df.at[index, 'scores'] = score
|
| 136 |
return filtered_df.sort_values(by="scores", ascending=False)
|
| 137 |
-
|
| 138 |
-
def
|
| 139 |
-
st.
|
| 140 |
-
platforms_filtered = self.platforms_df
|
| 141 |
-
|
| 142 |
-
if len(platforms_filtered) > 0:
|
| 143 |
-
st.write(f"Showing {len(platforms_filtered)} of {len(self.platforms_df)} platforms")
|
| 144 |
-
# cropped display
|
| 145 |
-
platform_config = {
|
| 146 |
-
"platform_url": st.column_config.LinkColumn("platform_url", display_text="Visit →"),
|
| 147 |
-
}
|
| 148 |
st.dataframe(
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
use_container_width=True,
|
| 152 |
hide_index=True
|
| 153 |
)
|
| 154 |
-
else:
|
| 155 |
-
st.info("No platforms match your search.")
|
| 156 |
-
|
| 157 |
|
| 158 |
if __name__ == "__main__":
|
| 159 |
agentbaseui = AgentBaseUI(agentbase_path="data/agentbase.csv", platforms_path="data/platforms.csv")
|
| 160 |
-
agentbaseui.
|
| 161 |
-
agentbaseui.
|
| 162 |
-
agentbaseui.
|
|
|
|
| 1 |
"""
|
| 2 |
+
AgentBase Visualisation UI.
|
| 3 |
|
| 4 |
Author: Arastun Mammadli
|
| 5 |
Date: [Current Date]
|
|
|
|
| 15 |
from retrieval.utils import load_queries
|
| 16 |
|
| 17 |
|
| 18 |
+
@st.cache_resource()
|
| 19 |
+
def load_retrievers(agentbase_path: str, index_configs: List[str]) -> Tuple[dict, dict]:
|
| 20 |
+
bm25s = {}
|
| 21 |
+
bges = {}
|
| 22 |
+
for idx_config in index_configs:
|
| 23 |
+
bm25s[idx_config] = BM25Retriever(agentbase_path, index_config=idx_config)
|
| 24 |
+
bges[idx_config] = DenseRetriever("BAAI/bge-large-en-v1.5", agentbase_path, index_config=idx_config)
|
| 25 |
+
return bm25s, bges
|
| 26 |
+
|
| 27 |
+
@st.cache_resource()
|
| 28 |
+
def load_agentbase_data(agentbase_path: str) -> pd.DataFrame:
|
| 29 |
+
return pd.read_csv(agentbase_path)
|
| 30 |
+
|
| 31 |
+
def keyword_filter(query, top_k, df, columns=["agent_name", "agent_description"]) -> List[Tuple[str, float]]:
|
| 32 |
"""
|
| 33 |
Simple keyword-based boolean filter across specified columns.
|
| 34 |
"""
|
|
|
|
|
|
|
| 35 |
mask = df[columns].astype(str).apply(
|
| 36 |
lambda col: col.str.contains(query, case=False, na=False)
|
| 37 |
).any(axis=1)
|
| 38 |
+
filtered_df = df[mask].head(top_k).copy()
|
| 39 |
filtered_df["scores"] = 1
|
| 40 |
return filtered_df
|
| 41 |
|
| 42 |
+
|
| 43 |
class AgentBaseUI:
|
| 44 |
"""
|
| 45 |
AgentBase Streamlit-based UI Components.
|
| 46 |
"""
|
|
|
|
| 47 |
def __init__(self, agentbase_path, platforms_path):
|
| 48 |
+
self.agents_df = load_agentbase_data(agentbase_path)
|
|
|
|
| 49 |
self.platforms_df = pd.read_csv(platforms_path)
|
| 50 |
+
self.bm25s, self.bges = load_retrievers(agentbase_path, index_configs=["v1", "naive"])
|
| 51 |
|
| 52 |
+
# selection options and defaults
|
| 53 |
self.retrieval_models = ["bge-large-en-v1.5", "bm25", "keyword"]
|
| 54 |
self.selected_model = "bge-large-en-v1.5"
|
| 55 |
self.indexing_configs = ["v1", "naive"]
|
| 56 |
+
self.indexing_config = "v1"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
def header_panel(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
st.set_page_config(page_title="AgentBase", layout="wide")
|
| 60 |
st.title("AgentBase Platform Demo")
|
| 61 |
st.write("A Large-Scale Agent Collection for Automated Agent Recommendation.")
|
| 62 |
+
|
| 63 |
st.subheader("🔍 Retrieval")
|
| 64 |
if "query" not in st.session_state:
|
| 65 |
st.session_state.query = ""
|
|
|
|
| 71 |
st.session_state.query = suggestion
|
| 72 |
|
| 73 |
col1, col2, col3 = st.columns([4, 1, 1])
|
| 74 |
+
with col1:
|
| 75 |
+
st.text_input("", placeholder="Type to search...", key="query")
|
| 76 |
with col2:
|
| 77 |
self.selected_model = st.selectbox("", self.retrieval_models, index=0)
|
| 78 |
with col3:
|
| 79 |
+
self.indexing_config = st.selectbox("", self.indexing_configs, index=0)
|
| 80 |
|
| 81 |
+
_, col2 = st.columns([2, 1])
|
| 82 |
+
with col2:
|
| 83 |
+
with st.expander("See explanation"):
|
| 84 |
+
st.write('''
|
| 85 |
+
- **Retrieval Models**:
|
| 86 |
+
- **BGE-Large**: a dense retrieval model.
|
| 87 |
+
- **BM25**: a sparse retrieval model.
|
| 88 |
+
- **Keyword**: simple boolean keyword matching.
|
| 89 |
+
- **Indexing Configurations**:
|
| 90 |
+
- **v1**: using all columns with priority ordering (e.g., name, description come first).
|
| 91 |
+
- **naive**: using agent name and description only.
|
| 92 |
+
''')
|
| 93 |
+
|
| 94 |
+
def retrieval_panel(self):
|
| 95 |
+
top_k = st.slider("Top K", 3, 100, 5)
|
| 96 |
+
if st.session_state.query:
|
| 97 |
+
self.filtered_df = self.retrieve_agents(st.session_state.query, top_k)
|
| 98 |
+
else:
|
| 99 |
+
self.filtered_df = self.agents_df.copy()
|
| 100 |
+
self.filtered_df['scores'] = 0.0
|
| 101 |
|
| 102 |
+
if len(self.filtered_df) > 0:
|
| 103 |
st.write(f"Showing {top_k} of {len(self.agents_df)} agents")
|
| 104 |
+
agent_config = { # clean column display
|
|
|
|
| 105 |
"agent_url": st.column_config.LinkColumn("agent_url", display_text="Visit →"),
|
| 106 |
"agent_description": st.column_config.TextColumn("agent_description", width="large"),
|
| 107 |
"agent_accessibility": st.column_config.TextColumn("agent_accessibility", width="small"),
|
| 108 |
}
|
| 109 |
+
key_columns = ['agent_name', 'platform_name', 'agent_description', 'agent_url', 'scores']
|
| 110 |
+
if (self.filtered_df['scores'] == 0).all(): key_columns.remove("scores")
|
| 111 |
+
st.dataframe(
|
| 112 |
+
self.filtered_df[key_columns].head(top_k),
|
| 113 |
+
column_config=agent_config,
|
| 114 |
+
use_container_width=True,
|
| 115 |
+
hide_index=True
|
| 116 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
else:
|
| 118 |
st.info("No agents match your search.")
|
| 119 |
|
|
|
|
| 123 |
Default maximum top_k of 100
|
| 124 |
"""
|
| 125 |
if self.selected_model == 'keyword':
|
| 126 |
+
return keyword_filter(query, top_k, self.agents_df)
|
| 127 |
elif self.selected_model == 'bm25':
|
| 128 |
+
res = self.bm25s[self.indexing_config].retrieve(query, top_k)
|
| 129 |
elif self.selected_model == 'bge-large-en-v1.5':
|
| 130 |
+
res = self.bges[self.indexing_config].retrieve(query, top_k)
|
| 131 |
else:
|
| 132 |
raise ValueError(f"Selected model must be one of {self.retrieval_models}")
|
| 133 |
|
|
|
|
| 138 |
score = dict(res).get(row['agent_id'], 0)
|
| 139 |
filtered_df.at[index, 'scores'] = score
|
| 140 |
return filtered_df.sort_values(by="scores", ascending=False)
|
| 141 |
+
|
| 142 |
+
def info_panel(self):
|
| 143 |
+
with st.expander(f"View AgentBase-v1.0"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
st.dataframe(
|
| 145 |
+
self.agents_df,
|
| 146 |
+
self.agents_df.columns,
|
| 147 |
+
use_container_width=True,
|
| 148 |
+
hide_index=True
|
| 149 |
+
)
|
| 150 |
+
st.dataframe(
|
| 151 |
+
self.platforms_df,
|
| 152 |
+
self.platforms_df.columns,
|
| 153 |
use_container_width=True,
|
| 154 |
hide_index=True
|
| 155 |
)
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
| 158 |
agentbaseui = AgentBaseUI(agentbase_path="data/agentbase.csv", platforms_path="data/platforms.csv")
|
| 159 |
+
agentbaseui.header_panel()
|
| 160 |
+
agentbaseui.retrieval_panel()
|
| 161 |
+
agentbaseui.info_panel()
|