Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import os
|
6 |
+
import google.generativeai as genai
|
7 |
+
from io import BytesIO
|
8 |
+
|
9 |
+
# Load environment variables
|
10 |
+
load_dotenv()
|
11 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
+
|
13 |
+
def get_gemini_response(prompt):
|
14 |
+
model = genai.GenerativeModel('gemini-pro')
|
15 |
+
response = model.generate_content(prompt)
|
16 |
+
return response.text
|
17 |
+
|
18 |
+
#######################
|
19 |
+
# REVISED FUNCTIONS
|
20 |
+
#######################
|
21 |
+
def estimate_cost(project_description):
|
22 |
+
prompt = f"Provide a cost estimation for the following project: {project_description}"
|
23 |
+
return get_gemini_response(prompt)
|
24 |
+
|
25 |
+
def assess_sustainability(project_description):
|
26 |
+
prompt = (
|
27 |
+
f"Analyze the sustainability and environmental impact of this project. "
|
28 |
+
f"Suggest eco-friendly materials, energy-saving approaches, and best practices "
|
29 |
+
f"that reduce the carbon footprint and ensure environmental compliance. "
|
30 |
+
f"Project Details: {project_description}"
|
31 |
+
)
|
32 |
+
return get_gemini_response(prompt)
|
33 |
+
|
34 |
+
def optimize_resources(project_description):
|
35 |
+
prompt = (
|
36 |
+
f"Suggest an optimal allocation of resources for this project, clearly specifying "
|
37 |
+
f"the types and quantities of personnel (e.g., project managers, engineers, specialists), "
|
38 |
+
f"equipment, software, and budget needed to complete the project effectively. "
|
39 |
+
f"Project Details: {project_description}"
|
40 |
+
)
|
41 |
+
return get_gemini_response(prompt)
|
42 |
+
|
43 |
+
def manage_risks(project_description):
|
44 |
+
prompt = (
|
45 |
+
f"Identify potential risks for this project. Provide them in categories such as: "
|
46 |
+
f"Financial, Operational, Compliance, Strategic, etc. For each category, "
|
47 |
+
f"describe the specific risks and suggest corresponding mitigation strategies. "
|
48 |
+
f"Project Details: {project_description}"
|
49 |
+
)
|
50 |
+
return get_gemini_response(prompt)
|
51 |
+
|
52 |
+
def prioritize_tasks(project_description):
|
53 |
+
prompt = f"List and prioritize critical tasks for the successful completion of this project: {project_description}"
|
54 |
+
return get_gemini_response(prompt)
|
55 |
+
|
56 |
+
def optimize_schedule(project_description):
|
57 |
+
# Renamed to Project Schedule
|
58 |
+
prompt = (
|
59 |
+
f"Create a project schedule (when and how to deliver) for the following project, "
|
60 |
+
f"including timeline and sequencing of tasks to ensure timely completion: {project_description}"
|
61 |
+
)
|
62 |
+
return get_gemini_response(prompt)
|
63 |
+
|
64 |
+
def get_project_scope(project_description):
|
65 |
+
prompt = (
|
66 |
+
f"Identify the project scope and deliverables for the following project, specifying "
|
67 |
+
f"goals, tasks, and features that need to be completed: {project_description}"
|
68 |
+
)
|
69 |
+
return get_gemini_response(prompt)
|
70 |
+
|
71 |
+
#######################
|
72 |
+
# STREAMLIT APP
|
73 |
+
#######################
|
74 |
+
st.set_page_config(page_title="PlanMaster AI", layout="wide")
|
75 |
+
|
76 |
+
# Title & Introduction
|
77 |
+
st.markdown("<h1 style='text-align: center; color: #ff6347;'>PlanMaster AI</h1>", unsafe_allow_html=True)
|
78 |
+
st.markdown(
|
79 |
+
"""
|
80 |
+
<div style='text-align: center; color: #4682b4;'>
|
81 |
+
<h3>Welcome to PlanMaster AI</h3>
|
82 |
+
<p>
|
83 |
+
This application leverages AI to help you plan and manage projects more effectively.
|
84 |
+
Simply provide a project description and select the type of analysis you want to perform.
|
85 |
+
</p>
|
86 |
+
</div>
|
87 |
+
""",
|
88 |
+
unsafe_allow_html=True
|
89 |
+
)
|
90 |
+
st.write("---")
|
91 |
+
|
92 |
+
# Sidebar
|
93 |
+
st.sidebar.markdown("<h2 style='color: #4CAF50;'>Select Analysis Task</h2>", unsafe_allow_html=True)
|
94 |
+
|
95 |
+
task_options = {
|
96 |
+
"Cost Estimation": "#ff6347",
|
97 |
+
"Sustainability Assessment": "#4682b4",
|
98 |
+
"Resource Optimization": "#32cd32",
|
99 |
+
"Risk Management": "#ff8c00",
|
100 |
+
"Task Prioritization": "#8a2be2",
|
101 |
+
"Project Schedule": "#ff1493",
|
102 |
+
"Project Scope": "#9400d3"
|
103 |
+
}
|
104 |
+
|
105 |
+
if "selected_task" not in st.session_state:
|
106 |
+
st.session_state["selected_task"] = None
|
107 |
+
|
108 |
+
for option, color in task_options.items():
|
109 |
+
if st.sidebar.button(option):
|
110 |
+
st.session_state["selected_task"] = option
|
111 |
+
|
112 |
+
selected_task = st.session_state["selected_task"]
|
113 |
+
|
114 |
+
# Project Description
|
115 |
+
if 'description_input' not in st.session_state:
|
116 |
+
st.session_state['description_input'] = ""
|
117 |
+
|
118 |
+
project_description = st.text_area("Enter Project Description", st.session_state['description_input'])
|
119 |
+
|
120 |
+
# Remove "Run All Analyses" button or comment it out
|
121 |
+
# if st.button("Run All Analyses"):
|
122 |
+
# st.session_state["selected_task"] = "Run All"
|
123 |
+
|
124 |
+
if selected_task:
|
125 |
+
st.write(f"## Current Task: {selected_task}")
|
126 |
+
else:
|
127 |
+
st.write("## Please select a task from the sidebar.")
|
128 |
+
|
129 |
+
def display_sample_table():
|
130 |
+
data = {
|
131 |
+
'Category': ['Materials', 'Labor', 'Equipment', 'Software', 'Services', 'Travel'],
|
132 |
+
'Cost Estimate ($)': [5000, 10000, 8000, 2000, 3000, 1500]
|
133 |
+
}
|
134 |
+
df = pd.DataFrame(data)
|
135 |
+
st.table(df)
|
136 |
+
|
137 |
+
def display_sample_chart():
|
138 |
+
data = {
|
139 |
+
'Risk Factor': ['Financial', 'Operational', 'Compliance', 'Strategic'],
|
140 |
+
'Likelihood (%)': [35, 20, 25, 20],
|
141 |
+
}
|
142 |
+
df = pd.DataFrame(data)
|
143 |
+
fig, ax = plt.subplots()
|
144 |
+
ax.bar(df['Risk Factor'], df['Likelihood (%)'], color='#ff8c00')
|
145 |
+
ax.set_title("Risk Factor Likelihood")
|
146 |
+
st.pyplot(fig)
|
147 |
+
|
148 |
+
if project_description.strip():
|
149 |
+
st.write("### Task Result")
|
150 |
+
if selected_task == "Cost Estimation":
|
151 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Cost Estimation Result 💸</h4>", unsafe_allow_html=True)
|
152 |
+
st.write(estimate_cost(project_description))
|
153 |
+
display_sample_table()
|
154 |
+
elif selected_task == "Sustainability Assessment":
|
155 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Sustainability Assessment Result 🌍</h4>", unsafe_allow_html=True)
|
156 |
+
st.write(assess_sustainability(project_description))
|
157 |
+
elif selected_task == "Resource Optimization":
|
158 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Resource Optimization Result 📊</h4>", unsafe_allow_html=True)
|
159 |
+
st.write(optimize_resources(project_description))
|
160 |
+
elif selected_task == "Risk Management":
|
161 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Risk Management Result ⚠️</h4>", unsafe_allow_html=True)
|
162 |
+
st.write(manage_risks(project_description))
|
163 |
+
display_sample_chart()
|
164 |
+
elif selected_task == "Task Prioritization":
|
165 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Task Prioritization Result 📋</h4>", unsafe_allow_html=True)
|
166 |
+
st.write(prioritize_tasks(project_description))
|
167 |
+
elif selected_task == "Project Schedule":
|
168 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Project Schedule Result 📅</h4>", unsafe_allow_html=True)
|
169 |
+
st.write(optimize_schedule(project_description))
|
170 |
+
elif selected_task == "Project Scope":
|
171 |
+
st.markdown(f"<h4 style='color: {task_options[selected_task]};'>Project Scope Result 📝</h4>", unsafe_allow_html=True)
|
172 |
+
st.write(get_project_scope(project_description))
|
173 |
+
|
174 |
+
########################
|
175 |
+
# CUSTOM PROMPT SECTION
|
176 |
+
########################
|
177 |
+
st.write("---")
|
178 |
+
st.write("### Run a Custom Prompt")
|
179 |
+
custom_prompt = st.text_area("Enter any additional prompt you'd like to run")
|
180 |
+
if st.button("Run Custom Prompt"):
|
181 |
+
if custom_prompt.strip():
|
182 |
+
custom_response = get_gemini_response(custom_prompt)
|
183 |
+
st.write("#### Custom Prompt Result")
|
184 |
+
st.write(custom_response)
|
185 |
+
else:
|
186 |
+
st.warning("Please enter a prompt before running.")
|
187 |
+
|
188 |
+
########################
|
189 |
+
# FOOTER
|
190 |
+
########################
|
191 |
+
st.write("---")
|
192 |
+
st.markdown(
|
193 |
+
"<p style='text-align: center; color: #808080;'>"
|
194 |
+
"Created by Nnenna Ginikanwa | Designed by Chidozie"
|
195 |
+
"</p>",
|
196 |
+
unsafe_allow_html=True
|
197 |
+
)
|