aminaj commited on
Commit
afa2153
·
verified ·
1 Parent(s): 3129bba

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -1
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel
3
  from contextlib import asynccontextmanager
4
  from langchain_community.document_loaders import PyPDFLoader
@@ -94,6 +94,16 @@ async def set_api_key(api_key: APIKey):
94
  os.environ["OPENAI_API_KEY"] = api_key.api_key
95
  return "API key set successfully!"
96
 
 
 
 
 
 
 
 
 
 
 
97
  ## POST - /load_file
98
  # Load the file, split it into document chunks, and upload the document embeddings into a vectorstore
99
  @app.post("/load_file/{llm}")
 
1
+ from fastapi import FastAPI, HTTPException, File, UploadFile
2
  from pydantic import BaseModel
3
  from contextlib import asynccontextmanager
4
  from langchain_community.document_loaders import PyPDFLoader
 
94
  os.environ["OPENAI_API_KEY"] = api_key.api_key
95
  return "API key set successfully!"
96
 
97
+ ## POST - /upload_file_on_server
98
+ @app.post("/upload_file_on_server")
99
+ async def upload_file_on_server(file: UploadFile = File(...)):
100
+ # Save the uploaded file to a temporary location
101
+ with open(file.filename, "wb") as buffer:
102
+ shutil.copyfileobj(file.file, buffer)
103
+
104
+ # Return a response
105
+ return {"filename": file.filename, "message": "File uploaded successfully"}
106
+
107
  ## POST - /load_file
108
  # Load the file, split it into document chunks, and upload the document embeddings into a vectorstore
109
  @app.post("/load_file/{llm}")