import streamlit as st import streamlit.components.v1 as components # Import Streamlit from logic import * import os # Set the page title and icon st.set_page_config( page_title="Neurons Lab RAG with KG Demo App", # page_icon=":robot:", page_icon="🧊", layout="wide", initial_sidebar_state="expanded" ) index= None # Define Streamlit widgets for user input st.sidebar.title("Settings") token = st.sidebar.text_input("OpenAI API Key", type="password", placeholder = 'sk...') KG_name = st.sidebar.text_input("Knowledge Graph Name", placeholder = 'Android_vs_iOS') st.sidebar.markdown(''' **Contact Us:**\n info@neurons-lab.com\n +44 330 027 2146\n [Neurons Lab Website](https://neurons-lab.com/)\n ''') KG_name = 'Android_vs_iOS' st.subheader("About the App") st.write("This application showcases the capabilities of Retrieval Augmented Generation (RAG) systems integrated with Knowledge Graphs (KGs).") st.write("Utilizing unstructured data like text files, PDF's or web pages, the app demonstrates how KGs enhance these systems by linking text chunks and extracting triples from documents to construct a graph.") st.write("The graph serves as a semantic-rich and symbolic-rich context, empowering Large Language Models (LLMs) to perform retrieval operations and generate high-quality results.") st.subheader("Knowledge Graph Visualization") st.subheader("") st.write("Sample Input: Content parsed from https://www.diffen.com/difference/Android_vs_iOS") st.subheader("") st.subheader("") HtmlFile = open(f"{KG_name}.html", 'r', encoding='utf-8') # Read the HTML file with open(f"{KG_name}.html", 'r', encoding='utf-8') as HtmlFile: source_code = HtmlFile.read() components.html(source_code,width=800, height=600, scrolling=False) st.subheader("Query the Knowledge Graph") st.write("Note: Provide OAI token to interact with the KG...") if len(token) != 0: if(os.path.exists(KG_name)): index = load_index(token,KG_name) else: st.write("NO FOLDER BY NAME") if (index != None): get_network_graph(index, KG_name) emb = get_embeddings(index) fig = get_visualize_embeddings(emb) # Plotly Chart st.plotly_chart(fig, use_container_width=True) with st.form("my_form"): user_query = st.text_input("Ask the KG ','") new_submitted = st.form_submit_button("Submit") if new_submitted: res = query_model(index,user_query) st.write(res)