File size: 1,113 Bytes
31d62a0
0f705a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31d62a0
058b4ca
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
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.json(out)

# st.write(stats)

# from tqdm.autonotebook import tqdm