Spaces:
Runtime error
Runtime error
working version of app
Browse files
app.py
CHANGED
|
@@ -7,40 +7,29 @@ OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
|
| 7 |
INDEX_NAME = 'realvest-data-v2'
|
| 8 |
EMBEDDING_MODEL = "text-embedding-ada-002" # OpenAI's best embeddings as of Apr 2023
|
| 9 |
|
| 10 |
-
### Pinecone
|
| 11 |
-
|
| 12 |
# initialize connection to pinecone (get API key at app.pinecone.io)
|
| 13 |
pinecone.init(
|
| 14 |
api_key=PINECONE_API_KEY,
|
| 15 |
environment="us-central1-gcp" # may be different, check at app.pinecone.io
|
| 16 |
)
|
| 17 |
-
|
| 18 |
index = pinecone.Index(INDEX_NAME)
|
|
|
|
|
|
|
| 19 |
|
| 20 |
### Main
|
| 21 |
-
|
| 22 |
# Create a text input field
|
| 23 |
query = st.text_input("What are you looking for?")
|
| 24 |
|
| 25 |
# Create a button
|
| 26 |
if st.button('Submit'):
|
| 27 |
-
# Display a response when the button is pressed
|
| 28 |
-
# st.text("Hi, {}".format(query))
|
| 29 |
-
print('click Submit')
|
| 30 |
|
| 31 |
-
### text-embedding
|
| 32 |
res = openai.Embedding.create(model=EMBEDDING_MODEL, input=[query], api_key=OPENAI_API_KEY)
|
| 33 |
-
st.json(res)
|
| 34 |
xq = res['data'][0]['embedding']
|
| 35 |
-
|
| 36 |
-
### query VectorDB
|
| 37 |
out = index.query(xq, top_k=3, include_metadata=True)
|
| 38 |
|
| 39 |
### display
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
# from tqdm.autonotebook import tqdm
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 7 |
INDEX_NAME = 'realvest-data-v2'
|
| 8 |
EMBEDDING_MODEL = "text-embedding-ada-002" # OpenAI's best embeddings as of Apr 2023
|
| 9 |
|
|
|
|
|
|
|
| 10 |
# initialize connection to pinecone (get API key at app.pinecone.io)
|
| 11 |
pinecone.init(
|
| 12 |
api_key=PINECONE_API_KEY,
|
| 13 |
environment="us-central1-gcp" # may be different, check at app.pinecone.io
|
| 14 |
)
|
|
|
|
| 15 |
index = pinecone.Index(INDEX_NAME)
|
| 16 |
+
stats = index.describe_index_stats()
|
| 17 |
+
print(f"Pinecone DB stats: {stats}")
|
| 18 |
|
| 19 |
### Main
|
|
|
|
| 20 |
# Create a text input field
|
| 21 |
query = st.text_input("What are you looking for?")
|
| 22 |
|
| 23 |
# Create a button
|
| 24 |
if st.button('Submit'):
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# ### call OpenAI text-embedding
|
| 27 |
res = openai.Embedding.create(model=EMBEDDING_MODEL, input=[query], api_key=OPENAI_API_KEY)
|
|
|
|
| 28 |
xq = res['data'][0]['embedding']
|
|
|
|
|
|
|
| 29 |
out = index.query(xq, top_k=3, include_metadata=True)
|
| 30 |
|
| 31 |
### display
|
| 32 |
+
print(f"{'*'*30}results #3: {out}")
|
| 33 |
+
st.write("Matched results")
|
| 34 |
+
for match in out['matches']:
|
| 35 |
+
st.write( match['id'] )
|
|
|
|
|
|
|
|
|