import streamlit as st import pandas as pd import matplotlib.pyplot as plt from dotenv import load_dotenv import os import google.generativeai as genai from io import BytesIO # Load environment variables load_dotenv() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) def get_gemini_response(prompt): model = genai.GenerativeModel('gemini-pro') response = model.generate_content(prompt) return response.text ####################### # REVISED FUNCTIONS ####################### def estimate_cost(project_description): prompt = f"Provide a cost estimation for the following project: {project_description}" return get_gemini_response(prompt) def assess_sustainability(project_description): prompt = ( f"Analyze the sustainability and environmental impact of this project. " f"Suggest eco-friendly materials, energy-saving approaches, and best practices " f"that reduce the carbon footprint and ensure environmental compliance. " f"Project Details: {project_description}" ) return get_gemini_response(prompt) def optimize_resources(project_description): prompt = ( f"Suggest an optimal allocation of resources for this project, clearly specifying " f"the types and quantities of personnel (e.g., project managers, engineers, specialists), " f"equipment, software, and budget needed to complete the project effectively. " f"Project Details: {project_description}" ) return get_gemini_response(prompt) def manage_risks(project_description): prompt = ( f"Identify potential risks for this project. Provide them in categories such as: " f"Financial, Operational, Compliance, Strategic, etc. For each category, " f"describe the specific risks and suggest corresponding mitigation strategies. " f"Project Details: {project_description}" ) return get_gemini_response(prompt) def prioritize_tasks(project_description): prompt = f"List and prioritize critical tasks for the successful completion of this project: {project_description}" return get_gemini_response(prompt) def optimize_schedule(project_description): # Renamed to Project Schedule prompt = ( f"Create a project schedule (when and how to deliver) for the following project, " f"including timeline and sequencing of tasks to ensure timely completion: {project_description}" ) return get_gemini_response(prompt) def get_project_scope(project_description): prompt = ( f"Identify the project scope and deliverables for the following project, specifying " f"goals, tasks, and features that need to be completed: {project_description}" ) return get_gemini_response(prompt) ####################### # STREAMLIT APP ####################### st.set_page_config(page_title="PlanMaster AI", layout="wide") # Title & Introduction st.markdown("

PlanMaster AI

", unsafe_allow_html=True) st.markdown( """

Welcome to PlanMaster AI

This application leverages AI to help you plan and manage projects more effectively. Simply provide a project description and select the type of analysis you want to perform.

""", unsafe_allow_html=True ) st.write("---") # Sidebar st.sidebar.markdown("

Select Analysis Task

", unsafe_allow_html=True) task_options = { "Cost Estimation": "#ff6347", "Sustainability Assessment": "#4682b4", "Resource Optimization": "#32cd32", "Risk Management": "#ff8c00", "Task Prioritization": "#8a2be2", "Project Schedule": "#ff1493", "Project Scope": "#9400d3" } if "selected_task" not in st.session_state: st.session_state["selected_task"] = None for option, color in task_options.items(): if st.sidebar.button(option): st.session_state["selected_task"] = option selected_task = st.session_state["selected_task"] # Project Description if 'description_input' not in st.session_state: st.session_state['description_input'] = "" project_description = st.text_area("Enter Project Description", st.session_state['description_input']) # Remove "Run All Analyses" button or comment it out # if st.button("Run All Analyses"): # st.session_state["selected_task"] = "Run All" if selected_task: st.write(f"## Current Task: {selected_task}") else: st.write("## Please select a task from the sidebar.") def display_sample_table(): data = { 'Category': ['Materials', 'Labor', 'Equipment', 'Software', 'Services', 'Travel'], 'Cost Estimate ($)': [5000, 10000, 8000, 2000, 3000, 1500] } df = pd.DataFrame(data) st.table(df) def display_sample_chart(): data = { 'Risk Factor': ['Financial', 'Operational', 'Compliance', 'Strategic'], 'Likelihood (%)': [35, 20, 25, 20], } df = pd.DataFrame(data) fig, ax = plt.subplots() ax.bar(df['Risk Factor'], df['Likelihood (%)'], color='#ff8c00') ax.set_title("Risk Factor Likelihood") st.pyplot(fig) if project_description.strip(): st.write("### Task Result") if selected_task == "Cost Estimation": st.markdown(f"

Cost Estimation Result 💸

", unsafe_allow_html=True) st.write(estimate_cost(project_description)) display_sample_table() elif selected_task == "Sustainability Assessment": st.markdown(f"

Sustainability Assessment Result 🌍

", unsafe_allow_html=True) st.write(assess_sustainability(project_description)) elif selected_task == "Resource Optimization": st.markdown(f"

Resource Optimization Result 📊

", unsafe_allow_html=True) st.write(optimize_resources(project_description)) elif selected_task == "Risk Management": st.markdown(f"

Risk Management Result ⚠️

", unsafe_allow_html=True) st.write(manage_risks(project_description)) display_sample_chart() elif selected_task == "Task Prioritization": st.markdown(f"

Task Prioritization Result 📋

", unsafe_allow_html=True) st.write(prioritize_tasks(project_description)) elif selected_task == "Project Schedule": st.markdown(f"

Project Schedule Result 📅

", unsafe_allow_html=True) st.write(optimize_schedule(project_description)) elif selected_task == "Project Scope": st.markdown(f"

Project Scope Result 📝

", unsafe_allow_html=True) st.write(get_project_scope(project_description)) ######################## # CUSTOM PROMPT SECTION ######################## st.write("---") st.write("### Run a Custom Prompt") custom_prompt = st.text_area("Enter any additional prompt you'd like to run") if st.button("Run Custom Prompt"): if custom_prompt.strip(): custom_response = get_gemini_response(custom_prompt) st.write("#### Custom Prompt Result") st.write(custom_response) else: st.warning("Please enter a prompt before running.") ######################## # FOOTER ######################## st.write("---") st.markdown( "

" "Created by Nnenna Ginikanwa | Designed by Chidozie" "

", unsafe_allow_html=True )