petrojm commited on
Commit
7801fa3
1 Parent(s): 48b6b86

changes to app and config

Browse files
Files changed (2) hide show
  1. app.py +8 -6
  2. config.yaml +1 -1
app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import sys
3
  import yaml
4
  import gradio as gr
5
- from datetime import datetime
6
 
7
  current_dir = os.path.dirname(os.path.abspath(__file__))
8
 
@@ -25,7 +25,9 @@ def handle_userinput(user_question, conversation_chain, history):
25
 
26
  return history, ""
27
  except Exception as e:
28
- return f"An error occurred: {str(e)}", ""
 
 
29
  else:
30
  return history, ""
31
 
@@ -33,10 +35,11 @@ def process_documents(files, collection_name, document_retrieval, vectorstore, c
33
  try:
34
  document_retrieval = DocumentRetrieval()
35
  _, _, text_chunks = parse_doc_universal(doc=files)
 
36
  print(text_chunks)
37
  embeddings = document_retrieval.load_embedding_model()
38
- timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
39
- collection_name = 'ekr_default_collection' + "-" + timestamp
40
  vectorstore = document_retrieval.create_vector_store(text_chunks, embeddings, output_db=save_location, collection_name=collection_name)
41
  document_retrieval.init_retriever(vectorstore)
42
  conversation_chain = document_retrieval.get_qa_retrieval_chain()
@@ -50,7 +53,6 @@ with open(CONFIG_PATH, 'r') as yaml_file:
50
  config = yaml.safe_load(yaml_file)
51
 
52
  prod_mode = config.get('prod_mode', False)
53
- #default_collection = 'ekr_default_collection'
54
 
55
  # Load env variables
56
  initialize_env_variables(prod_mode)
@@ -83,7 +85,7 @@ with gr.Blocks() as demo:
83
  gr.Markdown(caution_text)
84
 
85
  # Preprocessing events
86
- process_btn.click(process_documents, inputs=[docs, collection_name, document_retrieval, vectorstore, conversation_chain], outputs=[conversation_chain, vectorstore, document_retrieval, collection_name, setup_output], concurrency_limit=10)
87
 
88
  # Step 3: Chat with your data
89
  gr.Markdown("## 3️⃣ Chat with your document")
 
2
  import sys
3
  import yaml
4
  import gradio as gr
5
+ import uuid
6
 
7
  current_dir = os.path.dirname(os.path.abspath(__file__))
8
 
 
25
 
26
  return history, ""
27
  except Exception as e:
28
+ error_msg = f"An error occurred: {str(e)}"
29
+ history = history + [(user_question, error_msg)]
30
+ return history, ""
31
  else:
32
  return history, ""
33
 
 
35
  try:
36
  document_retrieval = DocumentRetrieval()
37
  _, _, text_chunks = parse_doc_universal(doc=files)
38
+ print(len(text_chunks))
39
  print(text_chunks)
40
  embeddings = document_retrieval.load_embedding_model()
41
+ collection_id = str(uuid.uuid4())
42
+ collection_name = f"collection_{collection_id}"
43
  vectorstore = document_retrieval.create_vector_store(text_chunks, embeddings, output_db=save_location, collection_name=collection_name)
44
  document_retrieval.init_retriever(vectorstore)
45
  conversation_chain = document_retrieval.get_qa_retrieval_chain()
 
53
  config = yaml.safe_load(yaml_file)
54
 
55
  prod_mode = config.get('prod_mode', False)
 
56
 
57
  # Load env variables
58
  initialize_env_variables(prod_mode)
 
85
  gr.Markdown(caution_text)
86
 
87
  # Preprocessing events
88
+ process_btn.click(process_documents, inputs=[docs, collection_name, document_retrieval, vectorstore, conversation_chain], outputs=[conversation_chain, vectorstore, document_retrieval, collection_name, setup_output], concurrency_limit=20)
89
 
90
  # Step 3: Chat with your data
91
  gr.Markdown("## 3️⃣ Chat with your document")
config.yaml CHANGED
@@ -11,7 +11,7 @@ llm:
11
  "do_sample": False
12
  "max_tokens_to_generate": 1200
13
  "coe": True #set as true if using Sambastudio CoE endpoint
14
- "select_expert": "llama3-8b" #set if using sncloud, SambaStudio CoE llm expert
15
  #sncloud CoE expert name -> "llama3-8b"
16
 
17
  retrieval:
 
11
  "do_sample": False
12
  "max_tokens_to_generate": 1200
13
  "coe": True #set as true if using Sambastudio CoE endpoint
14
+ "select_expert": "Meta-Llama-3.1-8B-Instruct" #set if using sncloud, SambaStudio CoE llm expert
15
  #sncloud CoE expert name -> "llama3-8b"
16
 
17
  retrieval: