Akkuvs/LangGraphAgenticAI
0
1 2import streamlit as st3import json4from src.Langgraphagenticai.ui.streamlitui.loadui import LoadStreamlitUI5from src.Langgraphagenticai.LLMS.groqllm import GroqLLM6from src.Langgraphagenticai.graph.graph_builder import GraphBuilder7from src.Langgraphagenticai.ui.streamlitui.display_result import DisplayResultStreamlit8 9# MAIN Function START10def load_langgraph_agenticai_app():11 """12 Loads and runs the LangGraph AgenticAI application with Streamlit UI.13 This function initializes the UI, handles user input, configures the LLM model,14 sets up the graph based on the selected use case, and displays the output while 15 implementing exception handling for robustness.16 """17 18 # Load UI19 ui = LoadStreamlitUI()20 user_input = ui.load_streamlit_ui()21 22 if not user_input:23 st.error("Error: Failed to load user input from the UI.")24 return25 26 # Text input for user message27 if st.session_state.IsFetchButtonClicked:28 user_message = st.session_state.timeframe 29 else :30 user_message = st.chat_input("Enter your message:")31 32 if user_message:33 try:34 # Configure LLM35 obj_llm_config = GroqLLM(user_controls_input=user_input)36 model = obj_llm_config.get_llm_model()37 38 if not model:39 st.error("Error: LLM model could not be initialized.")40 return41 42 # Initialize and set up the graph based on use case43 usecase = user_input.get('selected_usecase')44 if not usecase:45 st.error("Error: No use case selected.")46 return47 48 ## Graph Builder49 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 return56 57 except Exception as e:58 raise ValueError(f"Error Occurred with Exception : {e}")59 60 61 62 