HUANG-Stephanie commited on
Commit
f4c3d99
1 Parent(s): d2b07a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -17,6 +17,7 @@ from transformers import AutoProcessor
17
  from reportlab.pdfgen import canvas
18
  from reportlab.lib.pagesizes import letter
19
  from io import BytesIO
 
20
 
21
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), './colpali-main')))
22
 
@@ -165,6 +166,39 @@ async def recommendation(file: UploadFile = File(...), k: int = 10):
165
  response.headers['Content-Disposition'] = 'attachment; filename="results.pdf"'
166
 
167
  return response
168
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  if __name__ == "__main__":
170
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
17
  from reportlab.pdfgen import canvas
18
  from reportlab.lib.pagesizes import letter
19
  from io import BytesIO
20
+ from pymongo import MongoClient
21
 
22
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), './colpali-main')))
23
 
 
166
  response.headers['Content-Disposition'] = 'attachment; filename="results.pdf"'
167
 
168
  return response
169
+
170
+ def get_database():
171
+
172
+ # Provide the mongodb atlas url to connect python to mongodb using pymongo
173
+ CONNECTION_STRING = "mongodb://localhost:27017"
174
+
175
+ # Create a connection using MongoClient. You can import MongoClient or use pymongo.MongoClient
176
+ client = MongoClient(CONNECTION_STRING)
177
+
178
+ # Create the database for our example (we will use the same database throughout the tutorial
179
+ return client['cvquest-colpali']
180
+
181
+ dbname = get_database()
182
+ collection_name = dbname["files"]
183
+
184
+ item_1 = {
185
+ "_id" : "U1IT00001",
186
+ "item_name" : "Blender",
187
+ "max_discount" : "10%",
188
+ "batch_number" : "RR450020FRG",
189
+ "price" : 340,
190
+ "category" : "kitchen appliance"
191
+ }
192
+
193
+ item_2 = {
194
+ "_id" : "U1IT00002",
195
+ "item_name" : "Egg",
196
+ "category" : "food",
197
+ "quantity" : 12,
198
+ "price" : 36,
199
+ "item_description" : "brown country eggs"
200
+ }
201
+ collection_name.insert_many([item_1,item_2])
202
+
203
  if __name__ == "__main__":
204
  uvicorn.run(app, host="0.0.0.0", port=7860)