mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-14 17:03:29 +03:00
feat(visual): moved things around
This commit is contained in:
parent
4174f0693a
commit
5d66cd5223
1
files.py
1
files.py
@ -1,4 +1,5 @@
|
||||
import streamlit as st
|
||||
import os
|
||||
from loaders.audio import process_audio
|
||||
from loaders.txt import process_txt
|
||||
from loaders.csv import process_csv
|
||||
|
@ -1,6 +1,7 @@
|
||||
import tempfile
|
||||
from utils import compute_sha1_from_file
|
||||
from langchain.schema import Document
|
||||
import streamlit as st
|
||||
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
||||
|
||||
def process_file(vector_store, file, loader_class, file_suffix):
|
||||
|
40
main.py
40
main.py
@ -1,16 +1,14 @@
|
||||
# main.py
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import streamlit as st
|
||||
from sidebar import sidebar
|
||||
from files import file_uploader
|
||||
from question import chat_with_doc
|
||||
from langchain.embeddings.openai import OpenAIEmbeddings
|
||||
from langchain.vectorstores import SupabaseVectorStore
|
||||
from supabase import Client, create_client
|
||||
|
||||
|
||||
|
||||
# supabase_url = "https://fqgpcifsfmamprzldyiv.supabase.co"
|
||||
supabase_url = st.secrets.supabase_url
|
||||
supabase_key = st.secrets.supabase_service_key
|
||||
@ -20,16 +18,44 @@ supabase: Client = create_client(supabase_url, supabase_key)
|
||||
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
|
||||
vector_store = SupabaseVectorStore(supabase, embeddings, table_name="documents")
|
||||
|
||||
# Set the theme
|
||||
st.set_page_config(
|
||||
page_title="Second Brain",
|
||||
layout="wide",
|
||||
initial_sidebar_state="expanded",
|
||||
|
||||
|
||||
)
|
||||
|
||||
st.title("🧠 Second Brain 🧠")
|
||||
st.markdown("Store your knowledge in a vector store and query it with OpenAI's GPT-3/4.")
|
||||
st.markdown("---\n\n")
|
||||
|
||||
# Initialize session state variables
|
||||
if 'model' not in st.session_state:
|
||||
st.session_state['model'] = "gpt-3.5-turbo"
|
||||
if 'temperature' not in st.session_state:
|
||||
st.session_state['temperature'] = 0.0
|
||||
if 'chunk_size' not in st.session_state:
|
||||
st.session_state['chunk_size'] = 500
|
||||
if 'chunk_overlap' not in st.session_state:
|
||||
st.session_state['chunk_overlap'] = 0
|
||||
|
||||
# Create a radio button for user to choose between adding knowledge or asking a question
|
||||
user_choice = st.radio("Choose an action", ('Add Knowledge to the Brain', 'Ask a Question to the Brain'))
|
||||
|
||||
if user_choice == 'Add Knowledge to the Brain':
|
||||
# Display chunk size and overlap selection only when adding knowledge
|
||||
st.sidebar.title("Configuration")
|
||||
st.sidebar.markdown("Choose your chunk size and overlap for adding knowledge.")
|
||||
st.session_state['chunk_size'] = st.sidebar.slider("Select Chunk Size", 100, 1000, st.session_state['chunk_size'], 50)
|
||||
st.session_state['chunk_overlap'] = st.sidebar.slider("Select Chunk Overlap", 0, 100, st.session_state['chunk_overlap'], 10)
|
||||
file_uploader(supabase, openai_api_key, vector_store)
|
||||
elif user_choice == 'Ask a Question to the Brain':
|
||||
# Display model and temperature selection only when asking questions
|
||||
st.sidebar.title("Configuration")
|
||||
st.sidebar.markdown("Choose your model and temperature for asking questions.")
|
||||
st.session_state['model'] = st.sidebar.selectbox("Select Model", ["gpt-3.5-turbo", "gpt-4"], index=("gpt-3.5-turbo", "gpt-4").index(st.session_state['model']))
|
||||
st.session_state['temperature'] = st.sidebar.slider("Select Temperature", 0.0, 1.0, st.session_state['temperature'], 0.1)
|
||||
chat_with_doc(openai_api_key, vector_store)
|
||||
|
||||
sidebar(supabase)
|
||||
file_uploader(supabase,openai_api_key, vector_store)
|
||||
st.markdown("---\n\n")
|
||||
chat_with_doc(openai_api_key, vector_store)
|
||||
|
@ -3,16 +3,12 @@ from langchain.chains import ConversationalRetrievalChain
|
||||
from langchain.memory import ConversationBufferMemory
|
||||
from langchain.llms import OpenAI
|
||||
|
||||
|
||||
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
||||
|
||||
|
||||
def chat_with_doc(openai_api_key,vector_store):
|
||||
def chat_with_doc(openai_api_key, vector_store):
|
||||
question = st.text_input("## Ask a question")
|
||||
temperature = st.session_state.get("temperature", 0.0)
|
||||
model = st.session_state.get("model", "gpt-3.5-turbo")
|
||||
button = st.button("Ask")
|
||||
if button:
|
||||
qa = ConversationalRetrievalChain.from_llm(OpenAI(model_name=model, openai_api_key=openai_api_key, temperature=temperature), vector_store.as_retriever(), memory=memory)
|
||||
qa = ConversationalRetrievalChain.from_llm(OpenAI(model_name=st.session_state['model'], openai_api_key=openai_api_key, temperature=st.session_state['temperature']), vector_store.as_retriever(), memory=memory)
|
||||
result = qa({"question": question})
|
||||
st.write(result["answer"])
|
23
sidebar.py
23
sidebar.py
@ -2,31 +2,10 @@ import streamlit as st
|
||||
|
||||
|
||||
def sidebar(supabase):
|
||||
st.sidebar.title("Configuration")
|
||||
|
||||
|
||||
## Get the number of documents in the database
|
||||
st.sidebar.title("Database Information")
|
||||
number_of_docs = number_of_documents(supabase)
|
||||
## Display the number of documents in the database
|
||||
st.sidebar.markdown(f"**Docs in DB:** {number_of_docs}")
|
||||
|
||||
## Allow user to choose model between gpt-3.5-turbo and gpt-4
|
||||
model = st.sidebar.selectbox("Select Model", ["gpt-3.5-turbo", "gpt-4"])
|
||||
## Allow user to choose temperature between 0.0 and 1.0
|
||||
temperature = st.sidebar.slider("Select Temperature", 0.0, 1.0, 0.0, 0.1)
|
||||
## Allow user to choose chunk_size between 100 and 1000
|
||||
chunk_size = st.sidebar.slider("Select Chunk Size", 100, 1000, 500, 50)
|
||||
## Allow user to choose chunk_overlap between 0 and 100
|
||||
chunk_overlap = st.sidebar.slider("Select Chunk Overlap", 0, 100, 0, 10)
|
||||
|
||||
|
||||
## Save the user's choices
|
||||
st.session_state.model = model
|
||||
st.session_state.temperature = temperature
|
||||
st.session_state.chunk_size = chunk_size
|
||||
st.session_state.chunk_overlap = chunk_overlap
|
||||
|
||||
def number_of_documents(supabase):
|
||||
## Get the number of documents in the database
|
||||
documents = supabase.table("documents").select("id", count="exact").execute()
|
||||
return documents.count
|
Loading…
Reference in New Issue
Block a user