Files
vincent 63a95dec00 Implement new MCP server usage.
Rework Agents description
Add new logging info
2026-08-22 10:24:28 +09:00

161 lines
5.1 KiB
Python

from pathlib import Path
from shared_config import AgenticAIConfig, create_logger, logger
import streamlit as st
from dotenv import load_dotenv
from agent_workflows.orchestration import runAgenticWorkflow
from utilities.pdf_tools_v2 import export_to_pdf
from datetime import datetime
#2- Loading Env Variables
load_dotenv() # It will load all the Env Variables
#3- Set Page Config
st.set_page_config(
page_title="Simplilearn Capstone Project", #Show it in the Tab
page_icon="🤖",
layout="wide"
)
#4- Initialize Config
if "config" not in st.session_state:
st.session_state.config = AgenticAIConfig()
config = st.session_state.config
#5- Initialize Streamlit- Conversation History
if "chat_history" not in st.session_state:
st.session_state.chat_history=[]
#6- Setting dict for Available Models
#llm_model = "gpt-5-nano" #Output~ 0.4 US$ / 1M tokens
#llm_model = "gpt-4o-mini" #Output~ 0.6 US$ / 1M tokens
#llm_model = "gpt-5.4-nano" #Output~ 1.25 US$ / 1M tokens
#llm_model = "gpt-5-mini" #Output~ 2 US$ / 1M tokens
#llm_model = "gpt-5.4-mini" #Output~ 4.50 US$ / 1M tokens
#llm_model = "gpt-4o" #Output~ 10 US$ / 1M tokens
#llm_model = "gpt-5.5" #Output~ 30 US$ / 1M tokens
MODEL_REGISTRY={
"OpenAI":["gpt-4o-mini","gpt-5-mini","gpt-5.4-nano","gpt-4.1","gpt-4o","gpt-3.5-turbo"],
"Ollama":["llama3.1","gemma4:e4b","gpt-oss:20b","qwen2.5-coder:14b","mistral-small3.2"],
}
#7- Creating Sidebar
with st.sidebar:
st.title("LLM Configuration")
config.provider = st.selectbox(
"LLM Provider",
list(MODEL_REGISTRY.keys())
)
#Dynamic Model Selection Logic
available_models = MODEL_REGISTRY[config.provider]
config.model = st.selectbox(
"Model",
available_models
)
config.temperature= st.slider(
"Temperature",
min_value=0.0,
max_value=2.0,
value=config.temperature,
step=0.1
)
config.max_tokens=st.slider(
"Max Tokens",
min_value=100,
max_value=10000,
value=config.max_tokens,
step=100
)
st.divider()
# Display Current Configurations Separately
st.subheader("Current Configuration:")
st.write(f"**Provider:** {config.provider}")
st.write(f"**Model:** {config.model}")
st.write(f"**Temperature:** {config.temperature}")
st.write(f"**Max Token:** {config.max_tokens}")
#8- Setting Page Title
st.title("🤖 Simplilearn Agentic AI Capstone: Research and GTM Planning")
#9- Creating User Input Section
config.user_query = st.text_area(
"Enter the product or service you want to research and plan a GTM strategy: ",
value = config.user_query,
height=200,
placeholder = "Example: Electrical bicycle, Burger shop in Tokyo, New AI-powered project management tool targeting small businesses, ..."
)
# Create Response Button
if st.button("Generate Response", type="primary"):
if not config.user_query.strip():
st.warning("Please enter a prompt before clicking the button")
else:
#Create logger
if logger is not None:
if logger.hasHandlers():
logger.removeHandler(logger.handlers[0]) # Remove existing handlers
create_logger()
#Store the User Query for displaying in conversation History on Streamlit
st.session_state.chat_history.append(
{
"role": "user",
"message": config.user_query
}
)
logger.info("Product or service to research and plan a GTM strategy: "+config.user_query)
# Create a Spinner until response is generated
with st.spinner("AI Agent is Thinking..."):
# Call CrewAI FLow
runAgenticWorkflow(config)
#Export the final GTM document to PDF
logger.info("Creating PDF...")
pdf_fiename_prefix = "Agentic_AI_Generated_GTM_Document"
script_dir = Path(__file__).parent
target_dir = script_dir / "output"
target_dir.mkdir(parents=True, exist_ok=True)
now = datetime.now()
formatted_DateTime = now.strftime("%Y-%m-%d_%H%M%S")
pdfpath = f"""output/{pdf_fiename_prefix}_{formatted_DateTime}.pdf"""
export_to_pdf(
llm_response=config.response,
output_filename=pdfpath)
logger.info("PDF Exported Successfully at: "+pdfpath)
#Store the response for display in conversation history
st.session_state.chat_history.append(
{
"role": "assistant",
"message": config.response
}
)
st.session_state.config= config
#10- Creating Response Section
st.subheader("Conversation History")
for chat in st.session_state.chat_history:
if chat["role"]=="user":
with st.chat_message("user"):
st.write(chat["message"])
else:
with st.chat_message("assistant"):
st.write(chat["message"])
#11- Creating the button for Users to clear all the chats from the UI
if st.sidebar.button("Clear Chat"):
st.session_state.chat_history=[]
st.rerun()