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 ### Pinecone # 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) ### Main # Create a text input field query = st.text_input("What are you looking for?") # Create a button if st.button('Submit'): # Display a response when the button is pressed # st.text("Hi, {}".format(query)) print('click Submit') ### text-embedding res = openai.Embedding.create(model=EMBEDDING_MODEL, input=[query], api_key=OPENAI_API_KEY) st.json(res) xq = res['data'][0]['embedding'] ### query VectorDB out = index.query(xq, top_k=3, include_metadata=True) ### display st.write(out) # st.write(stats) # from tqdm.autonotebook import tqdm