Update main.py
Browse files
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
|
|
@@ -25,7 +25,6 @@ import docx2txt
|
|
| 25 |
import pptx
|
| 26 |
import os
|
| 27 |
import utils
|
| 28 |
-
import shutil
|
| 29 |
|
| 30 |
## APPLICATION LIFESPAN
|
| 31 |
# Load the environment variables using FastAPI lifespan event so that they are available throughout the application
|
|
@@ -96,36 +95,6 @@ async def set_api_key(api_key: APIKey):
|
|
| 96 |
os.environ["OPENAI_API_KEY"] = api_key.api_key
|
| 97 |
return "API key set successfully!"
|
| 98 |
|
| 99 |
-
## POST - /upload_file_on_server
|
| 100 |
-
@app.post("/upload_file_on_server")
|
| 101 |
-
async def upload_file_on_server(file: UploadFile = File(...)):
|
| 102 |
-
# file_content = file.read() # Load the document
|
| 103 |
-
|
| 104 |
-
# # Create a directory if it doesn't exist
|
| 105 |
-
data_dir = "data"
|
| 106 |
-
# # os.makedirs(data_dir, exist_ok=True)
|
| 107 |
-
|
| 108 |
-
# # Create a temporary file in the data directory
|
| 109 |
-
# with tempfile.NamedTemporaryFile(delete=False, dir=data_dir) as temp_file:
|
| 110 |
-
# temp_file.write(file_content) # Write the uploaded file content to the temporary file
|
| 111 |
-
# temp_file_path = temp_file.name # Get the path of the temporary file
|
| 112 |
-
# return temp_file_path
|
| 113 |
-
# Save the uploaded file to the temporary directory
|
| 114 |
-
#file_path = os.path.join(data_dir, file.filename)
|
| 115 |
-
#print(file_path)
|
| 116 |
-
|
| 117 |
-
# Save the uploaded file to a temporary location
|
| 118 |
-
# with open(file_path, "wb") as buffer:
|
| 119 |
-
# shutil.copyfileobj(file.file, buffer)
|
| 120 |
-
|
| 121 |
-
# with open(file_path, "wb") as f:
|
| 122 |
-
# f.write(file.file.read())
|
| 123 |
-
|
| 124 |
-
# Return a response
|
| 125 |
-
# return {"filename": file.filename, "message": "File uploaded successfully"}
|
| 126 |
-
# return file.filename
|
| 127 |
-
return "hiiiiiiiiiiiiiiiiiiiiiiiiiii"
|
| 128 |
-
|
| 129 |
## POST - /load_file
|
| 130 |
# Load the file, split it into document chunks, and upload the document embeddings into a vectorstore
|
| 131 |
@app.post("/load_file/{llm}")
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
from contextlib import asynccontextmanager
|
| 4 |
from langchain_community.document_loaders import PyPDFLoader
|
|
|
|
| 25 |
import pptx
|
| 26 |
import os
|
| 27 |
import utils
|
|
|
|
| 28 |
|
| 29 |
## APPLICATION LIFESPAN
|
| 30 |
# Load the environment variables using FastAPI lifespan event so that they are available throughout the application
|
|
|
|
| 95 |
os.environ["OPENAI_API_KEY"] = api_key.api_key
|
| 96 |
return "API key set successfully!"
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
## POST - /load_file
|
| 99 |
# Load the file, split it into document chunks, and upload the document embeddings into a vectorstore
|
| 100 |
@app.post("/load_file/{llm}")
|