Spaces:
Sleeping
Sleeping
angelesteban00
commited on
Commit
•
2fa7d52
1
Parent(s):
ab1da5f
- app.py +2 -2
- load_data_example.py +26 -0
app.py
CHANGED
@@ -68,8 +68,8 @@ with gr.Blocks(theme=Base(), title="MongoDB Atlas Vector Search + RAG Architectu
|
|
68 |
"""
|
69 |
# MongoDB Atlas Vector Search + RAG Architecture
|
70 |
""")
|
71 |
-
openai_api_key = gr.Textbox(label = "OpenAI API Key",
|
72 |
-
mongo_uri = gr.Textbox(label = "Mongo Atlas URI",
|
73 |
textbox = gr.Textbox(label="Enter your Question:")
|
74 |
with gr.Row():
|
75 |
button = gr.Button("Submit", variant="primary")
|
|
|
68 |
"""
|
69 |
# MongoDB Atlas Vector Search + RAG Architecture
|
70 |
""")
|
71 |
+
openai_api_key = gr.Textbox(label = "OpenAI API Key (sk-...)", type = "password", lines = 1)
|
72 |
+
mongo_uri = gr.Textbox(label = "Mongo Atlas URI (mongodb+srv://..)", type = "password", lines = 1)
|
73 |
textbox = gr.Textbox(label="Enter your Question:")
|
74 |
with gr.Row():
|
75 |
button = gr.Button("Submit", variant="primary")
|
load_data_example.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pymongo import MongoClient
|
2 |
+
from langchain.embeddings.openai import OpenAIEmbeddings
|
3 |
+
from langchain.vectorstores import MongoDBAtlasVectorSearch
|
4 |
+
from langchain.document_loaders import DirectoryLoader
|
5 |
+
from langchain.llms import OpenAI
|
6 |
+
from langchain.chains import RetrievalQA
|
7 |
+
import gradio as gr
|
8 |
+
from gradio.themes.base import Base
|
9 |
+
#import key_param
|
10 |
+
import os
|
11 |
+
|
12 |
+
mongo_uri = os.getenv("MONGO_URI")
|
13 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
14 |
+
|
15 |
+
client = MongoClient(mongo_uri)
|
16 |
+
dbName = "langchain_demo"
|
17 |
+
collectionName = "collection_of_text_blobs"
|
18 |
+
collection = client[dbName][collectionName]
|
19 |
+
|
20 |
+
loader = DirectoryLoader( './sample_files', glob="./*.txt", show_progress=True)
|
21 |
+
data = loader.load()
|
22 |
+
|
23 |
+
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
|
24 |
+
|
25 |
+
vectorStore = MongoDBAtlasVectorSearch.from_documents( data, embeddings, collection=collection, index_name="default" )
|
26 |
+
|