Spaces:
Runtime error
Runtime error
Commit
·
a261a54
1
Parent(s):
537006f
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,8 @@ import streamlit as st
|
|
| 2 |
from utils import *
|
| 3 |
import constants
|
| 4 |
|
| 5 |
-
# Creating Session State
|
|
|
|
| 6 |
if 'Website_URL' not in st.session_state:
|
| 7 |
st.session_state['Website_URL'] =''
|
| 8 |
if 'HuggingFace_API_Key' not in st.session_state:
|
|
@@ -13,6 +14,19 @@ if 'Pinecone_EBV' not in st.session_state:
|
|
| 13 |
st.session_state['Pinecone_ENV'] =''
|
| 14 |
if 'Pinecone_API_Key' not in st.session_state:
|
| 15 |
st.session_state['Pinecone_API_Key'] =''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
#
|
| 18 |
st.title('🤖 AI Assistance For Website')
|
|
@@ -65,7 +79,36 @@ submit = st.button("Search")
|
|
| 65 |
|
| 66 |
if submit:
|
| 67 |
#Proceed only if API keys are provided
|
| 68 |
-
if st.session_state['Website_URL'] !="" and st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_ENV'] !="" and st.session_state['Pinecone_API_Key']!="" :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
#Creating embeddings instance
|
| 71 |
embeddings=create_embeddings()
|
|
@@ -75,6 +118,8 @@ if submit:
|
|
| 75 |
index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],st.session_state['Pinecone_ENV'],st.session_state['Pinecone_Index'],embeddings)
|
| 76 |
st.write("Pinecone index retrieval done...")
|
| 77 |
|
|
|
|
|
|
|
| 78 |
#Fetch relavant documents from Pinecone index
|
| 79 |
relavant_docs=get_similar_docs(index,prompt,document_count)
|
| 80 |
st.write(relavant_docs)
|
|
@@ -89,7 +134,7 @@ if submit:
|
|
| 89 |
st.write("**Info**: "+document.page_content)
|
| 90 |
st.write("**Link**: "+ document.metadata['source'])
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
else:
|
| 95 |
st.sidebar.error("Ooopssss!!! Please provide API keys.....")
|
|
|
|
| 2 |
from utils import *
|
| 3 |
import constants
|
| 4 |
|
| 5 |
+
# Creating Session State Variables
|
| 6 |
+
|
| 7 |
if 'Website_URL' not in st.session_state:
|
| 8 |
st.session_state['Website_URL'] =''
|
| 9 |
if 'HuggingFace_API_Key' not in st.session_state:
|
|
|
|
| 14 |
st.session_state['Pinecone_ENV'] =''
|
| 15 |
if 'Pinecone_API_Key' not in st.session_state:
|
| 16 |
st.session_state['Pinecone_API_Key'] =''
|
| 17 |
+
if 'API_Key' not in st.session_state:
|
| 18 |
+
st.session_state['API_Key'] = ''
|
| 19 |
+
if 'history' not in st.session_state:
|
| 20 |
+
st.session_state['history'] = ''
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# clear the chat history from streamlit session state
|
| 25 |
+
def clear_history():
|
| 26 |
+
if 'history' in st.session_state:
|
| 27 |
+
del st.session_state['history']
|
| 28 |
+
|
| 29 |
+
|
| 30 |
|
| 31 |
#
|
| 32 |
st.title('🤖 AI Assistance For Website')
|
|
|
|
| 79 |
|
| 80 |
if submit:
|
| 81 |
#Proceed only if API keys are provided
|
| 82 |
+
if st.session_state['Website_URL'] !="" and st.session_state['HuggingFace_API_Key'] !="" and st.session_state['Pinecone_ENV'] !="" and st.session_state['Pinecone_API_Key']!="" and st.session_state['API_Key'] != '':
|
| 83 |
+
|
| 84 |
+
st.session_state['API_Key'] = st.text_input("Paste in your OPENAI API key?", type="password")
|
| 85 |
+
|
| 86 |
+
q = st.text_input('Ask a question about the content of your file:')
|
| 87 |
+
if q: # if the user entered a question and hit enter
|
| 88 |
+
if 'vs' in st.session_state: # if there's the vector store (user uploaded, split and embedded a file)
|
| 89 |
+
vector_store = st.session_state.vs
|
| 90 |
+
st.write(f'k: {k}')
|
| 91 |
+
answer = ask_and_get_answer(vector_store, q, k)
|
| 92 |
+
|
| 93 |
+
# text area widget for the LLM answer
|
| 94 |
+
st.text_area('LLM Answer: ', value=answer)
|
| 95 |
+
|
| 96 |
+
st.divider()
|
| 97 |
+
|
| 98 |
+
# if there's no chat history in the session state, create it
|
| 99 |
+
if 'history' not in st.session_state:
|
| 100 |
+
st.session_state.history = ''
|
| 101 |
+
|
| 102 |
+
# the current question and answer
|
| 103 |
+
value = f'Q: {q} \nA: {answer}'
|
| 104 |
+
|
| 105 |
+
st.session_state.history = f'{value} \n {"-" * 100} \n {st.session_state.history}'
|
| 106 |
+
h = st.session_state.history
|
| 107 |
+
|
| 108 |
+
# text area widget for the chat history
|
| 109 |
+
st.text_area(label='Chat History', value=h, key='history', height=400)
|
| 110 |
+
|
| 111 |
+
'''
|
| 112 |
|
| 113 |
#Creating embeddings instance
|
| 114 |
embeddings=create_embeddings()
|
|
|
|
| 118 |
index=pull_from_pinecone(st.session_state['Pinecone_API_Key'],st.session_state['Pinecone_ENV'],st.session_state['Pinecone_Index'],embeddings)
|
| 119 |
st.write("Pinecone index retrieval done...")
|
| 120 |
|
| 121 |
+
|
| 122 |
+
|
| 123 |
#Fetch relavant documents from Pinecone index
|
| 124 |
relavant_docs=get_similar_docs(index,prompt,document_count)
|
| 125 |
st.write(relavant_docs)
|
|
|
|
| 134 |
st.write("**Info**: "+document.page_content)
|
| 135 |
st.write("**Link**: "+ document.metadata['source'])
|
| 136 |
|
| 137 |
+
'''
|
| 138 |
|
| 139 |
else:
|
| 140 |
st.sidebar.error("Ooopssss!!! Please provide API keys.....")
|