marcellopoliti commited on
Commit
6e74ef2
β€’
1 Parent(s): 2c4fa9b

restyle app

Browse files
Files changed (2) hide show
  1. app.py +71 -1
  2. pages/ask_brian.py +0 -31
app.py CHANGED
@@ -6,6 +6,12 @@ from utils import get_chroma_client, get_embedding_function
6
  import hmac
7
  import streamlit as st
8
  import os
 
 
 
 
 
 
9
 
10
  __import__("pysqlite3")
11
  import sys
@@ -43,6 +49,70 @@ if not check_password():
43
  st.stop() # Do not continue if check_password is not True.
44
 
45
  # Main Streamlit app starts here
46
- st.write("# Brian Knowledge Base System! πŸ‘‹")
47
  client = get_chroma_client()
48
  default_embedding_function = get_embedding_function()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  import hmac
7
  import streamlit as st
8
  import os
9
+ import streamlit.components.v1 as components
10
+ from retrieve_kb import get_current_knowledge_bases, get_knowledge_base_information
11
+ import streamlit as st
12
+ import requests
13
+ import os
14
+ from dotenv import load_dotenv
15
 
16
  __import__("pysqlite3")
17
  import sys
 
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)
pages/ask_brian.py DELETED
@@ -1,31 +0,0 @@
1
- import streamlit as st
2
- import requests
3
-
4
- api_key = st.secrets["BRIAN_API_KEY"]
5
-
6
-
7
- def send_post_request(prompt, kb):
8
- url = " https://api.brianknows.org/api/v0/agent/knowledge"
9
- data = {"prompt": prompt, "kb": kb}
10
- headers = {
11
- "Content-Type": "application/json",
12
- "X-Brian-Api-Key": api_key, # Include the API key in the headers
13
- }
14
-
15
- response = requests.post(url, json=data, headers=headers)
16
-
17
- if response.status_code == 200:
18
- return response.json() # Returns the JSON response if successful
19
- else:
20
- return (
21
- response.status_code,
22
- response.text,
23
- ) # Returns the status code and error if not successful
24
-
25
-
26
- # Example usage:
27
- kb_name = st.text_input(label="kb_name")
28
- query = st.text_input(label="query")
29
- if st.button("askbrian"):
30
- result = send_post_request(query, kb_name)
31
- st.json(result)