File size: 7,688 Bytes
33fa3e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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("<h1 style='text-align: center; color: #ff6347;'>PlanMaster AI</h1>", unsafe_allow_html=True)
st.markdown(
    """
    <div style='text-align: center; color: #4682b4;'>
        <h3>Welcome to PlanMaster AI</h3>
        <p>
          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.
        </p>
    </div>
    """, 
    unsafe_allow_html=True
)
st.write("---")

# Sidebar
st.sidebar.markdown("<h2 style='color: #4CAF50;'>Select Analysis Task</h2>", 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"<h4 style='color: {task_options[selected_task]};'>Cost Estimation Result 💸</h4>", unsafe_allow_html=True)
        st.write(estimate_cost(project_description))
        display_sample_table()
    elif selected_task == "Sustainability Assessment":
        st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Sustainability Assessment Result 🌍</h4>", unsafe_allow_html=True)
        st.write(assess_sustainability(project_description))
    elif selected_task == "Resource Optimization":
        st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Resource Optimization Result 📊</h4>", unsafe_allow_html=True)
        st.write(optimize_resources(project_description))
    elif selected_task == "Risk Management":
        st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Risk Management Result ⚠️</h4>", unsafe_allow_html=True)
        st.write(manage_risks(project_description))
        display_sample_chart()
    elif selected_task == "Task Prioritization":
        st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Task Prioritization Result 📋</h4>", unsafe_allow_html=True)
        st.write(prioritize_tasks(project_description))
    elif selected_task == "Project Schedule":
        st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Project Schedule Result 📅</h4>", unsafe_allow_html=True)
        st.write(optimize_schedule(project_description))
    elif selected_task == "Project Scope":
        st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Project Scope Result 📝</h4>", 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(
    "<p style='text-align: center; color: #808080;'>"
    "Created by Nnenna Ginikanwa | Designed by Chidozie"
    "</p>", 
    unsafe_allow_html=True
)