File size: 2,393 Bytes
4e00df7
 
 
 
 
 
 
 
 
 
8a70a7b
 
4e00df7
 
 
 
 
033cc04
4e00df7
 
 
 
 
 
 
 
 
 
 
0a26e47
4e00df7
 
 
 
 
 
 
 
 
 
033cc04
 
 
 
 
 
 
 
 
4e00df7
 
033cc04
 
4e00df7
 
 
033cc04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
# main.py
import os
import tempfile

import streamlit as st
from question import chat_with_doc
from langchain.embeddings import HuggingFaceInferenceAPIEmbeddings
from langchain.vectorstores import SupabaseVectorStore
from supabase import Client, create_client

supabase_url = st.secrets.SUPABASE_URL
supabase_key = st.secrets.SUPABASE_KEY
openai_api_key = st.secrets.openai_api_key
anthropic_api_key = st.secrets.anthropic_api_key
hf_api_key = st.secrets.hf_api_key
supabase: Client = create_client(supabase_url, supabase_key)
self_hosted = st.secrets.self_hosted
username = st.secrets.username

# embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)


embeddings = HuggingFaceInferenceAPIEmbeddings(
    api_key=hf_api_key,
    model_name="BAAI/bge-large-en-v1.5"
)

vector_store = SupabaseVectorStore(supabase, embeddings, query_name='match_documents', table_name="documents")

models = ["meta-llama/Llama-2-70b-chat-hf", "mistralai/Mixtral-8x7B-Instruct-v0.1"]

if openai_api_key:
    models += ["gpt-3.5-turbo", "gpt-4"]

if anthropic_api_key:
    models += ["claude-v1", "claude-v1.3",
               "claude-instant-v1-100k", "claude-instant-v1.1-100k"]

# Set the theme
st.set_page_config(
    page_title="Securade.ai - Safety Copilot",
    page_icon="https://securade.ai/favicon.ico",
    layout="centered",
    initial_sidebar_state="collapsed",
    menu_items={
        "About": "# Securade.ai Safety Copilot v0.1\n [https://securade.ai](https://securade.ai)",
        "Get Help" : "https://securade.ai",
        "Report a Bug": "mailto:[email protected]"
    }
)

st.title("👷‍♂️ Safety Copilot 🦺")
st.markdown("Chat with your personal assistant about health and safety information.")

st.markdown("---\n\n")

# Initialize session state variables
if 'model' not in st.session_state:
    st.session_state['model'] = "meta-llama/Llama-2-70b-chat-hf"
if 'temperature' not in st.session_state:
    st.session_state['temperature'] = 0.1
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
if 'max_tokens' not in st.session_state:
    st.session_state['max_tokens'] = 500
if 'username' not in st.session_state:
    st.session_state['username'] = username

chat_with_doc(st.session_state['model'], vector_store, stats_db=supabase)

st.markdown("---\n\n")