realvest-app / app.py
neobot's picture
working version of app
05b3af6
raw
history blame
1.09 kB
import streamlit as st
import openai
import pinecone
PINECONE_API_KEY = st.secrets["PINECONE_API_KEY"]
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
INDEX_NAME = 'realvest-data-v2'
EMBEDDING_MODEL = "text-embedding-ada-002" # OpenAI's best embeddings as of Apr 2023
# initialize connection to pinecone (get API key at app.pinecone.io)
pinecone.init(
api_key=PINECONE_API_KEY,
environment="us-central1-gcp" # may be different, check at app.pinecone.io
)
index = pinecone.Index(INDEX_NAME)
stats = index.describe_index_stats()
print(f"Pinecone DB stats: {stats}")
### Main
# Create a text input field
query = st.text_input("What are you looking for?")
# Create a button
if st.button('Submit'):
# ### call OpenAI text-embedding
res = openai.Embedding.create(model=EMBEDDING_MODEL, input=[query], api_key=OPENAI_API_KEY)
xq = res['data'][0]['embedding']
out = index.query(xq, top_k=3, include_metadata=True)
### display
print(f"{'*'*30}results #3: {out}")
st.write("Matched results")
for match in out['matches']:
st.write( match['id'] )