|
def display_analysis_results(result): |
|
""" |
|
Process and display analysis results from agents' output. |
|
""" |
|
try: |
|
|
|
st.markdown("#### Detailed Insights") |
|
st.text(result) |
|
|
|
|
|
if isinstance(result, str) and "\n" in result: |
|
lines = result.split("\n") |
|
insights = [line for line in lines if line.strip()] |
|
|
|
|
|
st.markdown("#### Key Insights (Parsed)") |
|
for insight in insights: |
|
st.write(f"- {insight}") |
|
|
|
|
|
st.markdown("#### Example Visualization (If Applicable)") |
|
if "data:" in result.lower(): |
|
|
|
data_lines = [line for line in result.split("\n") if "data:" in line.lower()] |
|
data_points = [ |
|
{"Category": f"Point {i+1}", "Value": float(line.split(":")[-1].strip())} |
|
for i, line in enumerate(data_lines) if line.split(":")[-1].strip().replace('.', '', 1).isdigit() |
|
] |
|
if data_points: |
|
df = pd.DataFrame(data_points) |
|
fig = px.bar(df, x="Category", y="Value", title="Extracted Data Visualization") |
|
st.plotly_chart(fig) |
|
except Exception as e: |
|
st.error(f"Error processing results: {e}") |
|
|
|
if st.button("Run Analysis"): |
|
with st.spinner('Executing...'): |
|
try: |
|
start_time = time.time() |
|
result = crew.kickoff(inputs={"topic": business, "stakeholder": stakeholder}) |
|
execution_time = time.time() - start_time |
|
|
|
|
|
st.markdown("### Insights and Analysis") |
|
display_analysis_results(result) |
|
|
|
|
|
st.success(f"Analysis completed in {execution_time:.2f} seconds!") |
|
|
|
|
|
report_path = generate_pdf_report(result) |
|
with open(report_path, "rb") as file: |
|
st.download_button( |
|
label="Download Report as PDF", |
|
data=file, |
|
file_name="Business_Insights_Report.pdf", |
|
mime="application/pdf" |
|
) |
|
except Exception as e: |
|
st.error(f"An error occurred during execution: {e}") |
|
|