added main file
Browse files
src/langgraphagenticai/main.py
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
from src.langgraphagenticai.ui.streamlitui.loadui import LoadStreamlitUI
|
| 4 |
+
from src.langgraphagenticai.LLMS.groqllm import GroqLLM
|
| 5 |
+
from src.langgraphagenticai.graph.graph_builder import GraphBuilder
|
| 6 |
+
from src.langgraphagenticai.ui.streamlitui.display_result import DisplayResultStreamlit
|
| 7 |
+
|
| 8 |
+
# MAIN Function START
|
| 9 |
+
def load_langgraph_agenticai_app():
|
| 10 |
+
"""
|
| 11 |
+
Loads and runs the LangGraph AgenticAI application with Streamlit UI.
|
| 12 |
+
This function initializes the UI, handles user input, configures the LLM model,
|
| 13 |
+
sets up the graph based on the selected use case, and displays the output while
|
| 14 |
+
implementing exception handling for robustness.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
# Load UI
|
| 18 |
+
ui = LoadStreamlitUI()
|
| 19 |
+
user_input = ui.load_streamlit_ui()
|
| 20 |
+
|
| 21 |
+
if not user_input:
|
| 22 |
+
st.error("Error: Failed to load user input from the UI.")
|
| 23 |
+
return
|
| 24 |
+
|
| 25 |
+
# Text input for user message
|
| 26 |
+
if st.session_state.IsFetchButtonClicked:
|
| 27 |
+
user_message = st.session_state.timeframe
|
| 28 |
+
else :
|
| 29 |
+
user_message = st.chat_input("Enter your message:")
|
| 30 |
+
|
| 31 |
+
if user_message:
|
| 32 |
+
try:
|
| 33 |
+
# Configure LLM
|
| 34 |
+
obj_llm_config = GroqLLM(user_controls_input=user_input)
|
| 35 |
+
model = obj_llm_config.get_llm_model()
|
| 36 |
+
|
| 37 |
+
if not model:
|
| 38 |
+
st.error("Error: LLM model could not be initialized.")
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
+
# Initialize and set up the graph based on use case
|
| 42 |
+
usecase = user_input.get('selected_usecase')
|
| 43 |
+
if not usecase:
|
| 44 |
+
st.error("Error: No use case selected.")
|
| 45 |
+
return
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
### Graph Builder
|
| 49 |
+
graph_builder=GraphBuilder(model)
|
| 50 |
+
try:
|
| 51 |
+
graph = graph_builder.setup_graph(usecase)
|
| 52 |
+
DisplayResultStreamlit(usecase,graph,user_message).display_result_on_ui()
|
| 53 |
+
except Exception as e:
|
| 54 |
+
st.error(f"Error: Graph setup failed - {e}")
|
| 55 |
+
return
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
except Exception as e:
|
| 59 |
+
raise ValueError(f"Error Occurred with Exception : {e}")
|