MP44 commited on
Commit
73c3249
·
verified ·
1 Parent(s): c592e77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -21
app.py CHANGED
@@ -1,21 +1,40 @@
1
- import gradio as gr
2
- from ui.gradio_ui import get_ui # Main UI structure
3
- from style import custom_css # Custom CSS for styling
4
-
5
- # Import and initialize LangChain RAg chain for lawbot
6
- from modules.lawbot.rag_with_langchain import load_documents, split_documents, create_vectorstore, setup_rag_chain
7
-
8
- # Initialize RAg chain once at app startup
9
- documents = load_documents()
10
- docs = split_documents(documents)
11
- vectorstore = create_vectorstore(docs)
12
- qa_chain = setup_rag_chain(vectorstore)
13
-
14
- # Gradio app with custom CSS and UI
15
- with gr.Blocks(css=custom_css) as demo:
16
- get_ui() # Loads all tabs including PehchaanSetu and others
17
-
18
- # Launch the Gradio app
19
- if __name__ == "__main__":
20
- url = demo.launch()
21
- print(f"🚀 Saarthi app is running at: {url}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)