ohalkhateeb commited on
Commit
1232f3f
·
verified ·
1 Parent(s): fea418b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -6
app.py CHANGED
@@ -1,11 +1,43 @@
1
- from document_loader import load_html_documents
 
 
 
 
 
 
 
2
 
3
- if __name__ == "__main__":
4
- print("Starting Dubai Law Chatbot...")
5
 
6
- print("Loading documents...")
7
- documents = load_html_documents('./data')
8
- print(f"Loaded {len(documents)} documents.")
9
 
 
 
 
 
10
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain.chains import RetrievalQA
3
+ from langchain.llms import DeepseekLLM # Or your preferred LLM
4
+ from langchain.vectorstores import Chroma
5
+ from langchain.embeddings import HuggingFaceEmbeddings
6
+ import os
7
+ import preprocess # Import the preprocess module
8
+ import create_database # Import the create_database module
9
 
 
 
10
 
11
+ # --- Preprocessing and Database Creation ---
 
 
12
 
13
+ # Preprocess data if not already done
14
+ if not os.path.exists("db"): # Check if database exists
15
+ preprocess.preprocess_and_save("./documents", "preprocessed_data.json") # Update path
16
+ create_database.create_vector_database("preprocessed_data.json", "db")
17
 
18
+ # --- RAG Pipeline ---
19
 
20
+ # Load the vector database
21
+ embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
22
+ vector_db = Chroma(persist_directory="db", embedding_function=embedding_model)
23
+ retriever = vector_db.as_retriever(search_kwargs={"k": 3})
24
+
25
+ # Load your LLM
26
+ llm = DeepseekLLM(model_name="deepseek-ai/deepseek-coder-7b-instruct") # Update if needed
27
+
28
+ # Create the RetrievalQA chain
29
+ qa_chain = RetrievalQA(llm=llm, retriever=retriever)
30
+
31
+ # --- Gradio Interface ---
32
+
33
+ def chatbot_interface(question):
34
+ return qa_chain.run(question)
35
+
36
+ iface = gr.Interface(
37
+ fn=chatbot_interface,
38
+ inputs="text",
39
+ outputs="text",
40
+ title="Dubai Legislation AI Chatbot"
41
+ )
42
+
43
+ iface.launch()