File size: 2,502 Bytes
074a08c 6b838ad 83b16e8 6b838ad 7689d3e ba65b6c 0c20220 22157ce 6b838ad 83b16e8 6b838ad 7689d3e 83b16e8 04e4b3d 83b16e8 7689d3e 83b16e8 0c20220 4e67c84 074a08c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
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) |