marcellopoliti commited on
Commit
611f226
β€’
1 Parent(s): 6e74ef2
Files changed (2) hide show
  1. app.py +67 -53
  2. pages/manage_knowledge_box.py +5 -6
app.py CHANGED
@@ -21,6 +21,28 @@ sys.modules["sqlite3"] = sys.modules.pop("pysqlite3")
21
  st.set_page_config(page_title="Hello", page_icon="πŸ‘‹", layout="wide")
22
 
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def check_password():
25
  """Returns `True` if the user had the correct password."""
26
 
@@ -48,71 +70,63 @@ def check_password():
48
  if not check_password():
49
  st.stop() # Do not continue if check_password is not True.
50
 
 
51
  # Main Streamlit app starts here
52
  client = get_chroma_client()
53
  default_embedding_function = get_embedding_function()
54
 
55
- col1, col2, col3 = st.columns((1, 4, 1))
56
- with col2:
57
- st.image("https://brianknows.org/brian_logo.png", width=300)
58
- st.write("# Brian Knowledge Base System! πŸ‘‹")
59
-
60
- # Sidebar
61
- st.sidebar.header(("About"))
62
- st.sidebar.markdown(
63
- (
64
- "[Brian](https://www.brianknows.org/) Built on top of Brian API, Brian App offers an user interface for performing transactions in a non-custodial way, researching web3 info, and deploying smart contracts by prompt."
65
- )
66
- )
67
-
68
- st.sidebar.header(("Resources"))
69
- st.sidebar.markdown(
70
- (
71
- """
72
- - [Brian Documentation](https://docs.brianknows.org/)
73
- - [X (Twitter)](https://x.com/BrianknowsAI?mx=2)
74
- - [Linkedin](https://www.linkedin.com/company/brianknowsai/)
75
- - [Medium](https://medium.com/@BrianknowsAI)
76
- """
77
- )
78
- )
79
 
80
- components.iframe("https://www.brianknows.org/", height=650, scrolling=True)
 
 
 
81
 
82
- st.divider()
83
 
 
 
84
 
85
- st.markdown("## Ask Brian Anything")
86
- kb_name = "public-knowledge-box"
87
 
88
- load_dotenv()
89
- api_key = os.getenv("BRIAN_API_KEY")
 
 
90
 
91
 
92
- def send_post_request(prompt, kb):
93
- url = " https://api.brianknows.org/api/v0/agent/knowledge"
94
- data = {"prompt": prompt, "kb": kb}
95
- headers = {
96
- "Content-Type": "application/json",
97
- "X-Brian-Api-Key": api_key, # Include the API key in the headers
98
- }
99
 
100
- response = requests.post(url, json=data, headers=headers)
 
101
 
102
- if response.status_code == 200:
103
- return response.json() # Returns the JSON response if successful
104
- else:
105
- return (
106
- response.status_code,
107
- response.text,
108
- ) # Returns the status code and error if not successful
109
 
 
110
 
111
- # Example usage:
112
- kbs = get_current_knowledge_bases(client=client)
113
- kbs = (kb.name for kb in kbs)
114
- kb_name = st.selectbox("Select knowledge box", kbs)
115
- query = st.text_input(label="query")
116
- if st.button("askbrian"):
117
- result = send_post_request(query, kb_name)
118
- st.json(result)
 
 
 
 
 
 
 
 
 
 
 
 
21
  st.set_page_config(page_title="Hello", page_icon="πŸ‘‹", layout="wide")
22
 
23
 
24
+ def show_sidebar():
25
+ # Sidebar
26
+ st.sidebar.header(("About"))
27
+ st.sidebar.markdown(
28
+ (
29
+ "[Brian](https://www.brianknows.org/) Built on top of Brian API, Brian App offers an user interface for performing transactions in a non-custodial way, researching web3 info, and deploying smart contracts by prompt."
30
+ )
31
+ )
32
+
33
+ st.sidebar.header(("Resources"))
34
+ st.sidebar.markdown(
35
+ (
36
+ """
37
+ - [Brian Documentation](https://docs.brianknows.org/)
38
+ - [X (Twitter)](https://x.com/BrianknowsAI?mx=2)
39
+ - [Linkedin](https://www.linkedin.com/company/brianknowsai/)
40
+ - [Medium](https://medium.com/@BrianknowsAI)
41
+ """
42
+ )
43
+ )
44
+
45
+
46
  def check_password():
47
  """Returns `True` if the user had the correct password."""
48
 
 
70
  if not check_password():
71
  st.stop() # Do not continue if check_password is not True.
72
 
73
+
74
  # Main Streamlit app starts here
75
  client = get_chroma_client()
76
  default_embedding_function = get_embedding_function()
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
+ # Function to load a page
80
+ def load_page(page_name):
81
+ with open(f"pages/{page_name}", "r") as file:
82
+ exec(file.read(), globals())
83
 
 
84
 
85
+ client = get_chroma_client()
86
+ default_embedding_function = get_embedding_function()
87
 
88
+ show_sidebar()
 
89
 
90
+ col1, col2, col3 = st.columns((1, 4, 1))
91
+ with col2:
92
+ st.image("https://brianknows.org/brian_logo.png", width=300)
93
+ st.write("# Brian Knowledge Base System! πŸ‘‹")
94
 
95
 
96
+ tab1, tab2 = st.tabs(["AskBrian", "BrianApp"])
97
+ with tab1:
98
+ st.markdown("## Ask Brian Anything")
99
+ kb_name = "public-knowledge-box"
 
 
 
100
 
101
+ load_dotenv()
102
+ api_key = os.getenv("BRIAN_API_KEY")
103
 
104
+ def send_post_request(prompt, kb):
105
+ url = " https://api.brianknows.org/api/v0/agent/knowledge"
106
+ data = {"prompt": prompt, "kb": kb}
107
+ headers = {
108
+ "Content-Type": "application/json",
109
+ "X-Brian-Api-Key": api_key, # Include the API key in the headers
110
+ }
111
 
112
+ response = requests.post(url, json=data, headers=headers)
113
 
114
+ if response.status_code == 200:
115
+ return response.json() # Returns the JSON response if successful
116
+ else:
117
+ return (
118
+ response.status_code,
119
+ response.text,
120
+ ) # Returns the status code and error if not successful
121
+
122
+ # Example usage:
123
+ kbs = get_current_knowledge_bases(client=client)
124
+ kbs = (kb.name for kb in kbs)
125
+ kb_name = st.selectbox("Select knowledge box", kbs)
126
+ query = st.text_input(label="query")
127
+ if st.button("askbrian"):
128
+ result = send_post_request(query, kb_name)
129
+ st.json(result)
130
+
131
+ with tab2:
132
+ components.iframe("https://www.brianknows.org/", height=650, scrolling=True)
pages/manage_knowledge_box.py CHANGED
@@ -11,15 +11,14 @@ from openai import OpenAI
11
  import wave
12
  from dotenv import load_dotenv
13
 
 
14
  load_dotenv()
15
  openai_key = os.getenv("OPENAI_API_KEY")
16
 
17
- st.title("Get knowledge boxes")
18
- if st.button("Get current knowledge bases"):
19
- kbs = get_current_knowledge_bases(client=client)
20
- st.json(kbs)
21
-
22
- collection_name = st.text_input(label="knowledge base name")
23
  info = {}
24
  collection = None
25
 
 
11
  import wave
12
  from dotenv import load_dotenv
13
 
14
+
15
  load_dotenv()
16
  openai_key = os.getenv("OPENAI_API_KEY")
17
 
18
+ st.title("Manage collections")
19
+ kbs = get_current_knowledge_bases(client=client)
20
+ kbs = (kb.name for kb in kbs)
21
+ collection_name = st.selectbox("Select knowledge box", kbs)
 
 
22
  info = {}
23
  collection = None
24