Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,30 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import sys
|
| 3 |
import os
|
| 4 |
-
from
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from modules.lawbot.rag_with_langchain import (
|
| 7 |
-
load_documents,
|
| 8 |
-
split_documents,
|
| 9 |
-
create_vectorstore,
|
| 10 |
setup_rag_chain
|
| 11 |
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 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 |
-
|
| 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 |
-
|
| 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()
|
|
|