How to share the object between two routes. or is there any other way to achieve the following use case in Fastapi #6595
-
First Check
Commit to Help
Example Code@data.post("/readfileandstore/")
async def preprocess_file(file:UploadFile = File(...)):
if 'txt' in file.filename:
pipe_document=PreProcess.store_txt_data(file)
@data.post("/findanswer")
async def find_answer(data:dict):
answers=[]
question = data['question']
logging.info(question)
prediction_document = pipe_document.run(query=question, top_k_retriever=128, top_k_reader=2)
answers.append(post_processing(prediction_document))
return answersDescriptionI am trying to create a webapp which allows to upload users a file and can perform search and QnA on the same file. In the route "readfileandstore" , I am taking file from users and sending to other functions for futher steps. as this is a one time process, I am using one route. after , I need Pipe_document object to process further quires on the document. so is there any way to get the pipe_document in the second route. Operating SystemLinux Operating System DetailsNo response FastAPI VersionNa Python Versionna Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
No, you should store this object somewhere on the server and then access it using unique key from second endpoint |
Beta Was this translation helpful? Give feedback.
No, you should store this object somewhere on the server and then access it using unique key from second endpoint