Update interim.py
Browse files- interim.py +68 -69
interim.py
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
# add refrence (https://medium.com/@hanan.tabak/user-friendly-open-source-multi-agent-ai-business-consultant-on-crewai-and-streamlit-0f972feb1b74) + improvize
|
2 |
-
#=================
|
3 |
-
# Import Libraries
|
4 |
-
#=================
|
5 |
-
|
6 |
import streamlit as st
|
7 |
from crewai import Agent, Task, Crew
|
8 |
import os
|
@@ -12,29 +8,12 @@ import pandas as pd
|
|
12 |
import plotly.express as px
|
13 |
import time
|
14 |
|
15 |
-
#=================
|
16 |
-
# Add Streamlit Components
|
17 |
-
#=================
|
18 |
-
|
19 |
-
# Background
|
20 |
-
page_bg_img = '''
|
21 |
-
<style>
|
22 |
-
.stApp {
|
23 |
-
background-image: url("https://images.all-free-download.com/images/graphiclarge/abstract_bright_corporate_background_310453.jpg");
|
24 |
-
background-size: cover;
|
25 |
-
}
|
26 |
-
</style>
|
27 |
-
'''
|
28 |
-
st.markdown(page_bg_img, unsafe_allow_html=True)
|
29 |
-
|
30 |
# Title and Sidebar
|
31 |
st.title("Multi-Agent Business Consultant")
|
32 |
|
33 |
-
image_url = "https://cdn-icons-png.flaticon.com/512/1998/1998614.png"
|
34 |
-
st.sidebar.image(image_url, caption="", use_container_width=True)
|
35 |
st.sidebar.write(
|
36 |
-
"This
|
37 |
-
"
|
38 |
)
|
39 |
|
40 |
# User Inputs
|
@@ -42,28 +21,32 @@ business = st.text_input('Enter The Required Business Search Area', value="Artif
|
|
42 |
stakeholder = st.text_input('Enter The Stakeholder Team', value="Executives")
|
43 |
|
44 |
# Optional Customization
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
|
65 |
#=================
|
66 |
-
# LLM Object
|
67 |
#=================
|
68 |
llm = ChatGroq(groq_api_key=os.getenv("GROQ_API_KEY"), model="groq/llama-3.3-70b-versatile")
|
69 |
|
@@ -174,38 +157,54 @@ def generate_pdf_report(result):
|
|
174 |
pdf.output(report_path)
|
175 |
return report_path
|
176 |
|
177 |
-
|
178 |
-
|
|
|
179 |
try:
|
180 |
start_time = time.time()
|
181 |
-
|
182 |
-
|
183 |
|
184 |
-
# Display Results
|
185 |
st.markdown("### Insights and Analysis")
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
# Display Execution Time
|
189 |
-
st.success(f"Analysis completed in {
|
190 |
-
|
191 |
-
#
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
})
|
197 |
-
fig = px.bar(data, x="Metric", y="Value", title="Sample Metrics for Analysis")
|
198 |
-
st.plotly_chart(fig)
|
199 |
-
|
200 |
-
# Generate and Provide PDF Report
|
201 |
-
report_path = generate_pdf_report(result)
|
202 |
-
with open(report_path, "rb") as file:
|
203 |
-
st.download_button(
|
204 |
-
label="Download Report as PDF",
|
205 |
-
data=file,
|
206 |
-
file_name="Business_Insights_Report.pdf",
|
207 |
-
mime="application/pdf"
|
208 |
-
)
|
209 |
|
210 |
except Exception as e:
|
211 |
st.error(f"An error occurred during execution: {e}")
|
|
|
1 |
# add refrence (https://medium.com/@hanan.tabak/user-friendly-open-source-multi-agent-ai-business-consultant-on-crewai-and-streamlit-0f972feb1b74) + improvize
|
|
|
|
|
|
|
|
|
2 |
import streamlit as st
|
3 |
from crewai import Agent, Task, Crew
|
4 |
import os
|
|
|
8 |
import plotly.express as px
|
9 |
import time
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
# Title and Sidebar
|
12 |
st.title("Multi-Agent Business Consultant")
|
13 |
|
|
|
|
|
14 |
st.sidebar.write(
|
15 |
+
"This Business Consultant is built using Multi-Agent system. "
|
16 |
+
"Use this application to generate actionable business insights and data-driven analysis!"
|
17 |
)
|
18 |
|
19 |
# User Inputs
|
|
|
21 |
stakeholder = st.text_input('Enter The Stakeholder Team', value="Executives")
|
22 |
|
23 |
# Optional Customization
|
24 |
+
st.sidebar.subheader("Agent Customization")
|
25 |
+
|
26 |
+
# Display customization section in a collapsible expander
|
27 |
+
with st.sidebar.expander("Customize Agent Goals", expanded=False):
|
28 |
+
enable_customization = st.checkbox("Enable Custom Goals")
|
29 |
+
if enable_customization:
|
30 |
+
planner_goal = st.text_area(
|
31 |
+
"Planner Goal",
|
32 |
+
value="Develop a comprehensive plan focusing on market trends and strategies."
|
33 |
+
)
|
34 |
+
writer_goal = st.text_area(
|
35 |
+
"Writer Goal",
|
36 |
+
value="Craft engaging and actionable content based on analysis."
|
37 |
+
)
|
38 |
+
analyst_goal = st.text_area(
|
39 |
+
"Analyst Goal",
|
40 |
+
value="Perform advanced statistical analysis and generate key insights."
|
41 |
+
)
|
42 |
+
else:
|
43 |
+
planner_goal = "Develop a comprehensive plan focusing on market trends and strategies."
|
44 |
+
writer_goal = "Craft engaging and actionable content based on analysis."
|
45 |
+
analyst_goal = "Perform advanced statistical analysis and generate key insights."
|
46 |
+
|
47 |
|
48 |
#=================
|
49 |
+
# LLM Object
|
50 |
#=================
|
51 |
llm = ChatGroq(groq_api_key=os.getenv("GROQ_API_KEY"), model="groq/llama-3.3-70b-versatile")
|
52 |
|
|
|
157 |
pdf.output(report_path)
|
158 |
return report_path
|
159 |
|
160 |
+
|
161 |
+
if st.button("Generate Insights"):
|
162 |
+
with st.spinner('Processing...'):
|
163 |
try:
|
164 |
start_time = time.time()
|
165 |
+
results = crew.kickoff(inputs={"topic": business, "stakeholder": stakeholder})
|
166 |
+
elapsed_time = time.time() - start_time
|
167 |
|
168 |
+
# Parse and Display Results
|
169 |
st.markdown("### Insights and Analysis")
|
170 |
+
|
171 |
+
# Handle Raw Output
|
172 |
+
raw_output = getattr(results, "raw", None)
|
173 |
+
if raw_output:
|
174 |
+
st.markdown("#### Executive Summary")
|
175 |
+
st.write(raw_output)
|
176 |
+
else:
|
177 |
+
st.warning("No executive summary available.")
|
178 |
+
|
179 |
+
# Handle Task Outputs
|
180 |
+
tasks_output = getattr(results, "tasks_output", [])
|
181 |
+
if tasks_output:
|
182 |
+
st.markdown("#### Task Outputs")
|
183 |
+
for idx, task in enumerate(tasks_output):
|
184 |
+
task_description = getattr(task,"description", "No description available.")
|
185 |
+
task_raw = getattr(task, "raw", "No details available.")
|
186 |
+
st.subheader(f"Task {idx + 1}")
|
187 |
+
st.write(f"**Description:** {task_description}")
|
188 |
+
st.write(task_raw)
|
189 |
+
else:
|
190 |
+
st.warning("No task outputs available.")
|
191 |
+
|
192 |
+
# Display Token Usage
|
193 |
+
token_usage = getattr(results, "token_usage", None)
|
194 |
+
if token_usage:
|
195 |
+
st.markdown("#### Token Usage")
|
196 |
+
st.json(token_usage)
|
197 |
+
else:
|
198 |
+
st.warning("No token usage information available.")
|
199 |
|
200 |
# Display Execution Time
|
201 |
+
st.success(f"Analysis completed in {elapsed_time:.2f} seconds.")
|
202 |
+
|
203 |
+
# Generate PDF Report
|
204 |
+
if raw_output:
|
205 |
+
report_path = generate_pdf_report(raw_output)
|
206 |
+
with open(report_path, "rb") as report_file:
|
207 |
+
st.download_button("Download Report", data=report_file, file_name="Business_Report.pdf")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
except Exception as e:
|
210 |
st.error(f"An error occurred during execution: {e}")
|