File size: 2,501 Bytes
dfc72aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457c5ae
 
dfc72aa
457c5ae
 
 
 
 
 
 
dfc72aa
457c5ae
dfc72aa
457c5ae
 
dfc72aa
457c5ae
 
 
 
 
 
 
 
 
dfc72aa
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
def display_analysis_results(result):
    """
    Process and display analysis results from agents' output.
    """
    try:
        # Display the result text
        st.markdown("#### Detailed Insights")
        st.text(result)
        
        # Parse the result into segments if formatted
        if isinstance(result, str) and "\n" in result:
            lines = result.split("\n")
            insights = [line for line in lines if line.strip()]
            
            # Show insights as bullet points
            st.markdown("#### Key Insights (Parsed)")
            for insight in insights:
                st.write(f"- {insight}")

        # Generate a visualization if result contains numerical data
        st.markdown("#### Example Visualization (If Applicable)")
        if "data:" in result.lower():
            # Example parsing numerical data from result (adapt to your agent's output)
            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

            # Display Results
            st.markdown("### Insights and Analysis")
            display_analysis_results(result)

            # Execution Time
            st.success(f"Analysis completed in {execution_time:.2f} seconds!")

            # Generate PDF Report
            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}")