Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -18,23 +18,6 @@ db_name = 'sample_mflix'
|
|
18 |
collection_name = 'embedded_movies'
|
19 |
collection = client[db_name][collection_name]
|
20 |
|
21 |
-
## Create a vector search index
|
22 |
-
print ('Creating vector search index')
|
23 |
-
# collection.create_search_index(model={"definition": {"mappings":{
|
24 |
-
# "dynamic":True,
|
25 |
-
# "fields": {
|
26 |
-
# "plot_embedding": {
|
27 |
-
# "type": "knnVector",
|
28 |
-
# "dimensions": 1536,
|
29 |
-
# "similarity": "euclidean"
|
30 |
-
# }
|
31 |
-
# }
|
32 |
-
# }}, "name":'default'})
|
33 |
-
|
34 |
-
# sleep for minute
|
35 |
-
# print ('Waiting for vector index on field "embedding" to be created')
|
36 |
-
# time.sleep(60)
|
37 |
-
|
38 |
try:
|
39 |
vector_store = MongoDBAtlasVectorSearch(embedding=OpenAIEmbeddings(), collection=collection, index_name='vector_index', text_key='plot', embedding_key='plot_embedding')
|
40 |
|
@@ -44,9 +27,7 @@ except:
|
|
44 |
vector_store = None
|
45 |
|
46 |
def get_movies(message, history):
|
47 |
-
|
48 |
-
# movies = vector_store.similarity_search(message, 3)
|
49 |
-
print ('Searching for: ' + message)
|
50 |
try:
|
51 |
movies = vector_store.similarity_search(message, 3)
|
52 |
retrun_text = ''
|
@@ -60,7 +41,7 @@ def get_movies(message, history):
|
|
60 |
yield "Please clone the repo and add your open ai key as well as your MongoDB Atlas UR in the Secret Section of you Space\n OPENAI_API_KEY (your Open AI key) and MONGODB_ATLAS_CLUSTER_URI (0.0.0.0/0 whitelisted instance with Vector index created) \n\n For more information : https://mongodb.com/products/platform/atlas-vector-search"
|
61 |
|
62 |
|
63 |
-
demo = gr.ChatInterface(get_movies, examples=["What movies are scary?", "Find me a comedy", "Movies for kids"], title="Movies Atlas Vector Search", submit_btn="Search").queue()
|
64 |
|
65 |
if __name__ == "__main__":
|
66 |
demo.launch()
|
|
|
18 |
collection_name = 'embedded_movies'
|
19 |
collection = client[db_name][collection_name]
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
try:
|
22 |
vector_store = MongoDBAtlasVectorSearch(embedding=OpenAIEmbeddings(), collection=collection, index_name='vector_index', text_key='plot', embedding_key='plot_embedding')
|
23 |
|
|
|
27 |
vector_store = None
|
28 |
|
29 |
def get_movies(message, history):
|
30 |
+
|
|
|
|
|
31 |
try:
|
32 |
movies = vector_store.similarity_search(message, 3)
|
33 |
retrun_text = ''
|
|
|
41 |
yield "Please clone the repo and add your open ai key as well as your MongoDB Atlas UR in the Secret Section of you Space\n OPENAI_API_KEY (your Open AI key) and MONGODB_ATLAS_CLUSTER_URI (0.0.0.0/0 whitelisted instance with Vector index created) \n\n For more information : https://mongodb.com/products/platform/atlas-vector-search"
|
42 |
|
43 |
|
44 |
+
demo = gr.ChatInterface(get_movies, examples=["What movies are scary?", "Find me a comedy", "Movies for kids"], title="Movies Atlas Vector Search",description="This small chat uses a similarity search to find relevant movies, it uses an MongoDB Atlase Vector Search read more here: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-tutorial" submit_btn="Search").queue()
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
demo.launch()
|