Spaces:
Build error
Build error
UPDATE: load to supabase
Browse files
app.py
CHANGED
|
@@ -250,9 +250,9 @@ async def newChatbot(chatbotName: str, username: str):
|
|
| 250 |
|
| 251 |
|
| 252 |
@app.post("/loadPDF")
|
| 253 |
-
async def
|
| 254 |
-
source = pdf.filename
|
| 255 |
username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
|
|
|
| 256 |
pdf = await pdf.read()
|
| 257 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file:
|
| 258 |
temp_file.write(pdf)
|
|
@@ -281,20 +281,60 @@ async def addPDFData(vectorstore: str, pdf: UploadFile = File(...)):
|
|
| 281 |
|
| 282 |
|
| 283 |
@app.post("/loadImagePDF")
|
| 284 |
-
async def
|
|
|
|
| 285 |
source = pdf.filename
|
| 286 |
pdf = await pdf.read()
|
| 287 |
text = getTextFromImagePDF(pdfBytes=pdf)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
return {
|
| 289 |
-
"output":
|
| 290 |
-
"source": source
|
| 291 |
}
|
| 292 |
|
| 293 |
|
|
|
|
| 294 |
class AddText(BaseModel):
|
| 295 |
vectorstore: str
|
| 296 |
text: str
|
| 297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
|
| 300 |
@app.post("/addText")
|
|
@@ -393,12 +433,35 @@ async def getCount(vectorstore: str):
|
|
| 393 |
}
|
| 394 |
|
| 395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
@app.post("/getYoutubeTranscript")
|
| 397 |
-
async def
|
| 398 |
-
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
| 400 |
"source": "www.youtube.com"
|
| 401 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
|
| 404 |
@app.post("/analyzeData")
|
|
@@ -429,3 +492,9 @@ async def chatHistory(vectorstore: str):
|
|
| 429 |
username).eq(
|
| 430 |
"chatbotName", chatbotName).execute().data
|
| 431 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
|
| 252 |
@app.post("/loadPDF")
|
| 253 |
+
async def loadPDF(vectorstore: str, pdf: UploadFile = File(...)):
|
|
|
|
| 254 |
username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
| 255 |
+
source = pdf.filename
|
| 256 |
pdf = await pdf.read()
|
| 257 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as temp_file:
|
| 258 |
temp_file.write(pdf)
|
|
|
|
| 281 |
|
| 282 |
|
| 283 |
@app.post("/loadImagePDF")
|
| 284 |
+
async def loadImagePDF(vectorstore: str, pdf: UploadFile = File(...)):
|
| 285 |
+
username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
| 286 |
source = pdf.filename
|
| 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)
|
| 294 |
+
response = supabase.storage.from_("ConversAI").upload(file=dct, path=f"{fileName}_data.json")
|
| 295 |
+
response = (
|
| 296 |
+
supabase.table("ConversAI_ChatbotDataSources")
|
| 297 |
+
.insert({"username": username,
|
| 298 |
+
"chatbotName": chatbotName,
|
| 299 |
+
"dataSourceName": fileName,
|
| 300 |
+
"sourceEndpoint": "\loadImagePDF",
|
| 301 |
+
"sourceContentURL": os.path.join(os.environ["SUPABASE_PUBLIC_BASE_URL"], f"{fileName}_data.json")})
|
| 302 |
+
.execute()
|
| 303 |
+
)
|
| 304 |
return {
|
| 305 |
+
"output": "SUCCESS"
|
|
|
|
| 306 |
}
|
| 307 |
|
| 308 |
|
| 309 |
+
|
| 310 |
class AddText(BaseModel):
|
| 311 |
vectorstore: str
|
| 312 |
text: str
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
@app.post("/loadText")
|
| 316 |
+
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")
|
| 324 |
+
response = supabase.storage.from_("ConversAI").upload(file=dct, path=f"{fileName}_data.json")
|
| 325 |
+
response = (
|
| 326 |
+
supabase.table("ConversAI_ChatbotDataSources")
|
| 327 |
+
.insert({"username": username,
|
| 328 |
+
"chatbotName": chatbotName,
|
| 329 |
+
"dataSourceName": fileName,
|
| 330 |
+
"sourceEndpoint": "\loadText",
|
| 331 |
+
"sourceContentURL": os.path.join(os.environ["SUPABASE_PUBLIC_BASE_URL"], f"{fileName}_data.json")})
|
| 332 |
+
.execute()
|
| 333 |
+
)
|
| 334 |
+
return {
|
| 335 |
+
"output": "SUCCESS"
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
|
| 339 |
|
| 340 |
@app.post("/addText")
|
|
|
|
| 433 |
}
|
| 434 |
|
| 435 |
|
| 436 |
+
class YtTranscript(BaseModel):
|
| 437 |
+
vectorstore: str
|
| 438 |
+
urls: list[str]
|
| 439 |
+
|
| 440 |
+
|
| 441 |
@app.post("/getYoutubeTranscript")
|
| 442 |
+
async def getYoutubeTranscript(ytTranscript: YtTranscript):
|
| 443 |
+
vectorstore, urls = ytTranscript.vectorstore, ytTranscript.urls
|
| 444 |
+
username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
| 445 |
+
text = getTranscript(urls=urls)
|
| 446 |
+
dct = {
|
| 447 |
+
"output": text,
|
| 448 |
"source": "www.youtube.com"
|
| 449 |
}
|
| 450 |
+
dct = json.dumps(dct, indent = 1).encode("utf-8")
|
| 451 |
+
fileName = createDataSourceName(sourceName = "youtube")
|
| 452 |
+
response = supabase.storage.from_("ConversAI").upload(file=dct, path=f"{fileName}_data.json")
|
| 453 |
+
response = (
|
| 454 |
+
supabase.table("ConversAI_ChatbotDataSources")
|
| 455 |
+
.insert({"username": username,
|
| 456 |
+
"chatbotName": chatbotName,
|
| 457 |
+
"dataSourceName": fileName,
|
| 458 |
+
"sourceEndpoint": "\getYoutubeTranscript",
|
| 459 |
+
"sourceContentURL": os.path.join(os.environ["SUPABASE_PUBLIC_BASE_URL"], f"{fileName}_data.json")})
|
| 460 |
+
.execute()
|
| 461 |
+
)
|
| 462 |
+
return {
|
| 463 |
+
"output": "SUCCESS"
|
| 464 |
+
}
|
| 465 |
|
| 466 |
|
| 467 |
@app.post("/analyzeData")
|
|
|
|
| 492 |
username).eq(
|
| 493 |
"chatbotName", chatbotName).execute().data
|
| 494 |
return response
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
# @app.post("/trainChatbot")
|
| 498 |
+
# async def chatHistory(vectorstore: str):
|
| 499 |
+
# username, chatbotName = vectorstore.split("$")[1], vectorstore.split("$")[2]
|
| 500 |
+
# return response
|