MP44 commited on
Commit
61152f1
·
verified ·
1 Parent(s): 01c067d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -31
app.py CHANGED
@@ -1,40 +1,30 @@
1
- import gradio as gr
2
- import sys
3
  import os
4
- from ui.gradio_ui import get_ui
5
- from style import custom_css
 
 
 
 
 
 
6
  from modules.lawbot.rag_with_langchain import (
7
- load_documents,
8
- split_documents,
9
- create_vectorstore,
10
  setup_rag_chain
11
  )
12
 
13
- # Global variable to hold the chain
14
- qa_chain = None
 
 
 
 
 
15
 
16
- def initialize_saarthi():
17
- """Initialize the RAG pipeline only once."""
18
- global qa_chain
19
- if qa_chain is None:
20
- print("--- Initializing Saarthi Legal Engine ---")
21
- try:
22
- documents = load_documents()
23
- docs = split_documents(documents)
24
- vectorstore = create_vectorstore(docs)
25
- qa_chain = setup_rag_chain(vectorstore)
26
- print("--- Initialization Complete ---")
27
- except Exception as e:
28
- print(f"❌ Initialization Error: {e}")
29
- raise e
30
- return qa_chain
31
 
32
- # Create the Blocks interface
33
- with gr.Blocks(css=custom_css) as demo:
34
- # We call get_ui, but ensure your UI functions call initialize_saarthi()
35
- # when they need to perform a search.
36
- get_ui()
37
 
38
  if __name__ == "__main__":
39
- # Binding to 0.0.0.0 and port 7860 is required for Hugging Face Spaces
40
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
1
  import os
2
+ from dotenv import load_dotenv
3
+ load_dotenv()
4
+
5
+ import gradio as gr
6
+ from ui.gradio_ui import get_ui
7
+ from style import custom_css
8
+
9
+ # Import RAG pipeline
10
  from modules.lawbot.rag_with_langchain import (
11
+ load_documents,
12
+ split_documents,
13
+ create_vectorstore,
14
  setup_rag_chain
15
  )
16
 
17
+ def initialize_rag():
18
+ documents = load_documents()
19
+ docs = split_documents(documents)
20
+ vectorstore = create_vectorstore(docs)
21
+ return setup_rag_chain(vectorstore)
22
+
23
+ qa_chain = initialize_rag()
24
 
25
+ demo = get_ui(qa_chain)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ demo.css = custom_css
 
 
 
 
28
 
29
  if __name__ == "__main__":
30
+ demo.launch()