import streamlit as st from utils import get_chroma_client, get_embedding_function # streamlit_app.py import hmac import streamlit as st import os import streamlit.components.v1 as components from retrieve_kb import get_current_knowledge_bases, get_knowledge_base_information import streamlit as st import requests import os from dotenv import load_dotenv __import__("pysqlite3") import sys sys.modules["sqlite3"] = sys.modules.pop("pysqlite3") st.set_page_config(page_title="Hello", page_icon="👋", layout="wide") def show_sidebar(): # Sidebar st.sidebar.header(("About")) st.sidebar.markdown( ( "[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." ) ) st.sidebar.header(("Resources")) st.sidebar.markdown( ( """ - [Brian Documentation](https://docs.brianknows.org/) - [X (Twitter)](https://x.com/BrianknowsAI?mx=2) - [Linkedin](https://www.linkedin.com/company/brianknowsai/) - [Medium](https://medium.com/@BrianknowsAI) """ ) ) def check_password(): """Returns `True` if the user had the correct password.""" def password_entered(): """Checks whether a password entered by the user is correct.""" if hmac.compare_digest(st.session_state["password"], st.secrets["password"]): st.session_state["password_correct"] = True del st.session_state["password"] # Don't store the password. else: st.session_state["password_correct"] = False # Return True if the password is validated. if st.session_state.get("password_correct", False): return True # Show input for password. st.text_input( "Password", type="password", on_change=password_entered, key="password" ) if "password_correct" in st.session_state: st.error("😕 Password incorrect") return False if not check_password(): st.stop() # Do not continue if check_password is not True. # Main Streamlit app starts here client = get_chroma_client() default_embedding_function = get_embedding_function() # Function to load a page def load_page(page_name): with open(f"pages/{page_name}", "r") as file: exec(file.read(), globals()) client = get_chroma_client() default_embedding_function = get_embedding_function() show_sidebar() col1, col2, col3 = st.columns((1, 4, 1)) with col2: st.image("https://brianknows.org/brian_logo.png", width=300) st.write("# Brian Knowledge Base System! 👋") tab1, tab2 = st.tabs(["AskBrian", "BrianApp"]) with tab1: st.markdown("## Ask Brian Anything") kb_name = "public-knowledge-box" load_dotenv() api_key = os.getenv("BRIAN_API_KEY") def send_post_request(prompt, kb): url = " https://api.brianknows.org/api/v0/agent/knowledge" data = {"prompt": prompt, "kb": kb} headers = { "Content-Type": "application/json", "X-Brian-Api-Key": api_key, # Include the API key in the headers } response = requests.post(url, json=data, headers=headers) if response.status_code == 200: return response.json() # Returns the JSON response if successful else: return ( response.status_code, response.text, ) # Returns the status code and error if not successful # Example usage: kbs = get_current_knowledge_bases(client=client) kbs = (kb.name for kb in kbs) kb_name = st.selectbox("Select knowledge box", kbs) query = st.text_input(label="query") if st.button("askbrian"): result = send_post_request(query, kb_name) st.json(result) with tab2: components.iframe("https://www.brianknows.org/", height=650, scrolling=True)