Spaces:
No application file
No application file
Create upload_file.py
Browse files- src/utils/upload_file.py +35 -0
src/utils/upload_file.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.prepare_vectordb import PrepareVectorDB
|
| 2 |
+
from typing import List, Tuple
|
| 3 |
+
from utils.load_config import LoadConfig
|
| 4 |
+
from utils.summarizer import Summarizer
|
| 5 |
+
|
| 6 |
+
APPCFG = LoadConfig()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class UploadFile:
|
| 10 |
+
@staticmethod
|
| 11 |
+
def process_uploaded_files(files_dir: List, chatbot: List, rag_with_dropdown: str) -> Tuple:
|
| 12 |
+
if rag_with_dropdown == "Upload doc: Process for RAG":
|
| 13 |
+
prepare_vectordb_instance = PrepareVectorDB(data_directory=files_dir,
|
| 14 |
+
persist_directory=APPCFG.custom_persist_directory,
|
| 15 |
+
embedding_model_engine=APPCFG.embedding_model_engine,
|
| 16 |
+
chunk_size=APPCFG.chunk_size,
|
| 17 |
+
chunk_overlap=APPCFG.chunk_overlap)
|
| 18 |
+
prepare_vectordb_instance.prepare_and_save_vectordb()
|
| 19 |
+
chatbot.append(
|
| 20 |
+
(" ", "Uploaded files are ready. Please ask your question"))
|
| 21 |
+
elif rag_with_dropdown == "Upload doc: Give Full summary":
|
| 22 |
+
final_summary = Summarizer.summarize_the_pdf(file_dir=files_dir[0],
|
| 23 |
+
max_final_token=APPCFG.max_final_token,
|
| 24 |
+
token_threshold=APPCFG.token_threshold,
|
| 25 |
+
gpt_model=APPCFG.llm_engine,
|
| 26 |
+
temperature=APPCFG.temperature,
|
| 27 |
+
summarizer_llm_system_role=APPCFG.summarizer_llm_system_role,
|
| 28 |
+
final_summarizer_llm_system_role=APPCFG.final_summarizer_llm_system_role,
|
| 29 |
+
character_overlap=APPCFG.character_overlap)
|
| 30 |
+
chatbot.append(
|
| 31 |
+
(" ", final_summary))
|
| 32 |
+
else:
|
| 33 |
+
chatbot.append(
|
| 34 |
+
(" ", "If you would like to upload a PDF, please select your desired action in 'rag_with' dropdown."))
|
| 35 |
+
return "", chatbot
|