DrishtiSharma's picture
Update test.py
dfc72aa verified
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}")