Rauhan commited on
Commit
6747b31
1 Parent(s): 8821135

UPDATE: load to supabase

Browse files
Files changed (1) hide show
  1. app.py +35 -6
app.py CHANGED
@@ -260,7 +260,8 @@ async def loadPDF(vectorstore: str, pdf: UploadFile = File(...)):
260
  text = extractTextFromPdf(temp_file_path)
261
  os.remove(temp_file_path)
262
  dct = {
263
- "output": text
 
264
  }
265
  dct = json.dumps(dct, indent = 1).encode("utf-8")
266
  fileName = createDataSourceName(sourceName = source)
@@ -287,7 +288,8 @@ async def loadImagePDF(vectorstore: str, pdf: UploadFile = File(...)):
287
  pdf = await pdf.read()
288
  text = getTextFromImagePDF(pdfBytes=pdf)
289
  dct = {
290
- "output": text
 
291
  }
292
  dct = json.dumps(dct, indent = 1).encode("utf-8")
293
  fileName = createDataSourceName(sourceName = source)
@@ -317,7 +319,8 @@ async def loadText(addTextConfig: AddText):
317
  vectorstore, text = addTextConfig.vectorstore, addTextConfig.text
318
  username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
319
  dct = {
320
- "output": text
 
321
  }
322
  dct = json.dumps(dct, indent = 1).encode("utf-8")
323
  fileName = createDataSourceName(sourceName = "Text")
@@ -383,14 +386,40 @@ async def addQAPairData(addQaPair: AddQAPair):
383
  }
384
 
385
 
 
 
 
 
 
 
 
386
  @app.post("/loadWebURLs")
387
- async def addWebsite(vectorstore: str, websiteUrls: list[str]):
388
- text = extractTextFromUrlList(urls=websiteUrls)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  return {
390
- "output": text
391
  }
392
 
393
 
 
394
  @app.post("/answerQuery")
395
  async def answerQuestion(query: str, vectorstore: str, llmModel: str = "llama3-70b-8192"):
396
  username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
 
260
  text = extractTextFromPdf(temp_file_path)
261
  os.remove(temp_file_path)
262
  dct = {
263
+ "output": text,
264
+ "source": source
265
  }
266
  dct = json.dumps(dct, indent = 1).encode("utf-8")
267
  fileName = createDataSourceName(sourceName = source)
 
288
  pdf = await pdf.read()
289
  text = getTextFromImagePDF(pdfBytes=pdf)
290
  dct = {
291
+ "output": text,
292
+ "source": source
293
  }
294
  dct = json.dumps(dct, indent = 1).encode("utf-8")
295
  fileName = createDataSourceName(sourceName = source)
 
319
  vectorstore, text = addTextConfig.vectorstore, addTextConfig.text
320
  username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
321
  dct = {
322
+ "output": text,
323
+ "source": "Text"
324
  }
325
  dct = json.dumps(dct, indent = 1).encode("utf-8")
326
  fileName = createDataSourceName(sourceName = "Text")
 
386
  }
387
 
388
 
389
+
390
+ class LoadWebsite(BaseModel):
391
+ vectorstore: str
392
+ urls: list[str]
393
+ source: str
394
+
395
+
396
  @app.post("/loadWebURLs")
397
+ async def loadWebURLs(loadWebsite: LoadWebsite):
398
+ vectorstore, urls, source = loadWebsite.vectorstore, loadWebsite.urls, loadWebsite.source
399
+ username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
400
+ text = extractTextFromUrlList(urls=urls)
401
+ dct = {
402
+ "output": text,
403
+ "source": source
404
+ }
405
+ dct = json.dumps(dct, indent = 1).encode("utf-8")
406
+ fileName = createDataSourceName(sourceName = source)
407
+ response = supabase.storage.from_("ConversAI").upload(file=dct, path=f"{fileName}_data.json")
408
+ response = (
409
+ supabase.table("ConversAI_ChatbotDataSources")
410
+ .insert({"username": username,
411
+ "chatbotName": chatbotName,
412
+ "dataSourceName": fileName,
413
+ "sourceEndpoint": "\loadWebURLs",
414
+ "sourceContentURL": os.path.join(os.environ["SUPABASE_PUBLIC_BASE_URL"], f"{fileName}_data.json")})
415
+ .execute()
416
+ )
417
  return {
418
+ "output": "SUCCESS"
419
  }
420
 
421
 
422
+
423
  @app.post("/answerQuery")
424
  async def answerQuestion(query: str, vectorstore: str, llmModel: str = "llama3-70b-8192"):
425
  username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]