esemsc-am4224 commited on
Commit
e8847f3
ยท
1 Parent(s): 6d774e5

feat: added streamlit platform prototype

Browse files
platform/__init__.py ADDED
File without changes
platform/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (171 Bytes). View file
 
platform/__pycache__/database.cpython-312.pyc ADDED
Binary file (5.61 kB). View file
 
platform/agentbase.db ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55ff49e995742f88b3efa6d0736a58bcf47b987dbfa91a228f5ad1c64a8a03db
3
+ size 6701056
platform/database.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ AgentBase SQLite3 Database Connector.
3
+
4
+ This module implements general-purpose functions to access, manipulate and query the AgentBase
5
+ database platform.
6
+ 1. Schema Initialisation
7
+ 2. Database Connection and Query Execution
8
+ 3. Data Insertion (e.g., from temporary CSV files, TODO: updates through web scraping)
9
+
10
+ Author: Arastun Mammadli
11
+ Date: [Current Date]
12
+ """
13
+
14
+ import json
15
+ import pandas as pd
16
+ import numpy as np
17
+ import sqlite3
18
+ from sentence_transformers import SentenceTransformer
19
+
20
+
21
+ class SQLiteConnector:
22
+ """
23
+ A class to handle SQLite database connections and operations.
24
+ """
25
+
26
+ def __init__(self, database_file):
27
+ self.conn = sqlite3.connect(database_file)
28
+ self.cursor = self.conn.cursor()
29
+ self.init_schema()
30
+
31
+ def init_schema(self):
32
+ """
33
+ Initialise the datbase schema (run once).
34
+ (1) Platform Entity, (2) Agent Entity, (3) Embeddings Table (optional)
35
+ """
36
+ self.conn.execute("""
37
+ CREATE TABLE IF NOT EXISTS platforms (
38
+ platform_id TEXT PRIMARY KEY,
39
+ platform_name TEXT,
40
+ platform_url TEXT
41
+ )
42
+ """)
43
+ self.conn.execute("""
44
+ CREATE TABLE IF NOT EXISTS agents (
45
+ agent_id TEXT PRIMARY KEY,
46
+ platform_id INTEGER,
47
+ agent_name TEXT,
48
+ platform_name TEXT,
49
+ agent_description TEXT,
50
+ agent_category TEXT,
51
+ agent_usage TEXT, -- JSON string
52
+ usage_example TEXT, -- JSON string
53
+ agent_url TEXT,
54
+ agent_accessibility TEXT,
55
+ update_time TEXT,
56
+ misc TEXT,
57
+ FOREIGN KEY (platform_id) REFERENCES platforms(platform_id)
58
+ )
59
+ """)
60
+ self.conn.execute("""
61
+ CREATE TABLE IF NOT EXISTS embeddings (
62
+ agent_id TEXT,
63
+ embedding_model TEXT, -- e.g., 'all-MiniLM-L6-v2'
64
+ field TEXT, -- 'description', 'combined', etc.
65
+ embedding BLOB, -- numpy array as bytes
66
+ PRIMARY KEY (agent_id, embedding_model, field),
67
+ FOREIGN KEY (agent_id) REFERENCES agents(agent_id)
68
+ )
69
+ """)
70
+ self.conn.commit()
71
+
72
+ def insert_platform(self, platform_csv):
73
+ """
74
+ Insert a mock platform from a CSV file
75
+ """
76
+
77
+ df = pd.read_csv(platform_csv)
78
+ df.to_sql('platforms', self.conn, if_exists='replace', index=False)
79
+ self.conn.commit()
80
+
81
+ def insert_agent(self, agent_csv):
82
+ """
83
+ Insert mock agents from a CSV file
84
+ """
85
+
86
+ df = pd.read_csv(agent_csv)
87
+ df.to_sql('agents', self.conn, if_exists='replace', index=False)
88
+ self.conn.commit()
89
+
90
+ def execute_query(self, query, params=None):
91
+ if params:
92
+ self.cursor.execute(query, params)
93
+ else:
94
+ self.cursor.execute(query)
95
+ self.conn.commit()
96
+ return self.cursor.fetchall()
97
+
98
+ def load_all_as_df(self):
99
+ """
100
+ Loads all platforms and agents from database as a pandas dataframe.
101
+ """
102
+
103
+ platforms_df = pd.read_sql_query("SELECT * FROM platforms", self.conn)
104
+ agents_df = pd.read_sql_query("SELECT * FROM agents", self.conn)
105
+ return platforms_df, agents_df
106
+
107
+ def close(self):
108
+ self.conn.close()
109
+
110
+
111
+ if __name__ == "__main__":
112
+ db_file = "agentbase.db"
113
+ platforms_csv = f"../data_collection/extracted_data/platforms.csv"
114
+ agents_csv = f"../data_collection/extracted_data/cleaned/agentbase_cleaned.csv"
115
+
116
+ # connect & insert
117
+ db_connector = SQLiteConnector(db_file)
118
+ db_connector.insert_platform(platforms_csv)
119
+ db_connector.insert_agent(agents_csv)
120
+
121
+ # test
122
+ # platforms, agents = db_connector.load_all_as_df()
123
+ # print(platforms)
124
+ db_connector.close()
platform/interface.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ AgentBase Visualisation Demo.
3
+
4
+ Author: Arastun Mammadli
5
+ Date: [Current Date]
6
+ """
7
+
8
+ import streamlit as st
9
+ import pandas as pd
10
+ import numpy as np
11
+
12
+ from database import SQLiteConnector
13
+
14
+
15
+ def retrieve_data(df, search_term, search_columns, method='baseline'):
16
+ """
17
+ Retrieve data from the loaded DataFrame based on the specified method.
18
+ """
19
+
20
+ if method == 'baseline': return keyword_filter(df, search_term, search_columns)
21
+
22
+ def keyword_filter(df, keyword, columns):
23
+ """
24
+ Simple keyword-based boolean filter across specified columns.
25
+ """
26
+
27
+ if not keyword: return df
28
+
29
+ mask = df[columns].astype(str).apply(
30
+ lambda col: col.str.contains(keyword, case=False, na=False)
31
+ ).any(axis=1)
32
+ return df[mask]
33
+
34
+
35
+ class AgentBaseUI:
36
+ """
37
+ AgentBase Streamlit-based UI Components.
38
+ """
39
+
40
+ def __init__(self, db_path):
41
+ # loading the data
42
+ self.db_connector = SQLiteConnector(db_path)
43
+ self.platforms_df, self.agents_df = self.db_connector.load_all_as_df()
44
+
45
+ def show_header(self):
46
+ st.set_page_config(page_title="AgentBase", layout="wide")
47
+ st.title("AgentBase Platform Demo")
48
+ st.write("A Large-Scale Agent Collection for Automated Agent Recommendation.")
49
+ st.subheader("๐Ÿ” Retrieval")
50
+ self.search_term = st.text_input("Test our retrieval models", placeholder="Type to search...")
51
+
52
+ def show_platforms(self):
53
+ st.header("Platforms")
54
+ platforms_filtered = retrieve_data(
55
+ self.platforms_df,
56
+ self.search_term,
57
+ ['platform_id', 'platform_name', 'platform_url']
58
+ )
59
+
60
+ if len(platforms_filtered) > 0:
61
+ st.write(f"Showing {len(platforms_filtered)} of {len(self.platforms_df)} platforms")
62
+ # cropped display
63
+ platform_config = {
64
+ "platform_url": st.column_config.LinkColumn("platform_url", display_text="Visit โ†’"),
65
+ }
66
+ st.dataframe(
67
+ platforms_filtered,
68
+ column_config=platform_config,
69
+ use_container_width=True,
70
+ hide_index=True
71
+ )
72
+ else:
73
+ st.info("No platforms match your search.")
74
+
75
+ def show_agents(self):
76
+ st.header("Agents")
77
+ agents_filtered = retrieve_data(
78
+ self.agents_df,
79
+ self.search_term,
80
+ ['agent_id', 'agent_name', 'agent_description', 'agent_category']
81
+ )
82
+
83
+ if len(agents_filtered) > 0:
84
+ st.write(f"Showing {len(agents_filtered)} of {len(self.agents_df)} agents")
85
+ # cropped display
86
+ agent_config = {
87
+ "agent_url": st.column_config.LinkColumn("agent_url", display_text="Visit โ†’"),
88
+ "agent_description": st.column_config.TextColumn("agent_description", width="large"),
89
+ "agent_accessibility": st.column_config.TextColumn("agent_accessibility", width="small"),
90
+ }
91
+
92
+ # option to show details
93
+ if st.toggle("Show detailed view"):
94
+ st.dataframe(
95
+ agents_filtered,
96
+ column_config=agent_config,
97
+ use_container_width=True,
98
+ hide_index=True
99
+ )
100
+ else:
101
+ key_columns = ['agent_name', 'platform_id', 'agent_category', 'agent_accessibility', 'agent_url']
102
+ st.dataframe(
103
+ agents_filtered[key_columns],
104
+ column_config=agent_config,
105
+ use_container_width=True,
106
+ hide_index=True
107
+ )
108
+ else:
109
+ st.info("No agents match your search.")
110
+
111
+
112
+ if __name__ == "__main__":
113
+ agentbaseui = AgentBaseUI(db_path="agentbase.db")
114
+ agentbaseui.show_header()
115
+ agentbaseui.show_agents()
116
+ agentbaseui.show_platforms()