angelesteban00 commited on
Commit
1299579
1 Parent(s): cbd1f0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -9,21 +9,21 @@ 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
- # Define the text embedding model
21
- embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
22
 
23
- # Initialize the Vector Store
24
- vectorStore = MongoDBAtlasVectorSearch( collection, embeddings, index_name="default" )
25
 
26
- def query_data(query):
27
  # Convert question to vector using OpenAI embeddings
28
  # Perform Atlas Vector Search using Langchain's vectorStore
29
  # similarity_search returns MongoDB documents most similar to the query
@@ -65,6 +65,7 @@ with gr.Blocks(theme=Base(), title="Question Answering App using Vector Search +
65
  # Question Answering App using Atlas Vector Search + RAG Architecture
66
  """)
67
  openai_api_key = gr.Textbox(label = "OpenAI 3.5 API Key", value = "sk-", lines = 1)
 
68
  textbox = gr.Textbox(label="Enter your Question:")
69
  with gr.Row():
70
  button = gr.Button("Submit", variant="primary")
@@ -74,6 +75,9 @@ with gr.Blocks(theme=Base(), title="Question Answering App using Vector Search +
74
 
75
  # Call query_data function upon clicking the Submit button
76
 
77
- button.click(query_data, textbox, openai_api_key, outputs=[output1, output2])
 
 
 
78
 
79
  demo.launch()
 
9
  #import key_param
10
  import os
11
 
12
+ def query_data(query):
13
+ #mongo_uri = os.getenv("MONGO_URI")
14
+ #openai_api_key = os.getenv("OPENAI_API_KEY")
15
 
16
+ client = MongoClient(mongo_uri)
17
+ dbName = "langchain_demo"
18
+ collectionName = "collection_of_text_blobs"
19
+ collection = client[dbName][collectionName]
20
 
21
+ # Define the text embedding model
22
+ embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
23
 
24
+ # Initialize the Vector Store
25
+ vectorStore = MongoDBAtlasVectorSearch( collection, embeddings, index_name="default" )
26
 
 
27
  # Convert question to vector using OpenAI embeddings
28
  # Perform Atlas Vector Search using Langchain's vectorStore
29
  # similarity_search returns MongoDB documents most similar to the query
 
65
  # Question Answering App using Atlas Vector Search + RAG Architecture
66
  """)
67
  openai_api_key = gr.Textbox(label = "OpenAI 3.5 API Key", value = "sk-", lines = 1)
68
+ mongo_uri = gr.Textbox(label = "Mongo URI", value = "mongodb+srv://", lines = 1)
69
  textbox = gr.Textbox(label="Enter your Question:")
70
  with gr.Row():
71
  button = gr.Button("Submit", variant="primary")
 
75
 
76
  # Call query_data function upon clicking the Submit button
77
 
78
+ button.click(query_data,
79
+ inputs=[textbox, openai_api_key, mongo_uri],
80
+ outputs=[output1, output2]
81
+ )
82
 
83
  demo.launch()