Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +96 -156
src/streamlit_app.py
CHANGED
|
@@ -1,164 +1,104 @@
|
|
| 1 |
-
# app.py (Updated sections)
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
import plotly.express as px
|
| 5 |
import plotly.graph_objects as go
|
|
|
|
| 6 |
from streamlit_option_menu import option_menu
|
| 7 |
-
from data_generator import generate_synthetic_procurement_data
|
| 8 |
-
from ai_agents import LLMPoweredProcurementAgent, IntelligentRiskAgent
|
| 9 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
st.rerun()
|
| 98 |
-
|
| 99 |
-
with col2:
|
| 100 |
-
if st.button("π Who are my best vendors?"):
|
| 101 |
-
st.rerun()
|
| 102 |
-
|
| 103 |
-
with col3:
|
| 104 |
-
if st.button("β οΈ What risks should I worry about?"):
|
| 105 |
-
st.rerun()
|
| 106 |
-
|
| 107 |
-
# Enhanced AI Insights with LLM
|
| 108 |
-
elif selected == "π€ AI Insights":
|
| 109 |
-
st.markdown("### π§ Advanced AI Analysis")
|
| 110 |
-
|
| 111 |
-
# Vendor deep-dive analysis
|
| 112 |
-
st.markdown("#### π Vendor Performance Deep Dive")
|
| 113 |
-
|
| 114 |
-
selected_vendor = st.selectbox(
|
| 115 |
-
"Select vendor for AI analysis:",
|
| 116 |
-
options=st.session_state.po_df['vendor'].unique()
|
| 117 |
-
)
|
| 118 |
-
|
| 119 |
-
if st.button("π Generate AI Analysis", type="primary"):
|
| 120 |
-
with st.spinner(f'π€ AI is performing deep analysis of {selected_vendor}...'):
|
| 121 |
-
vendor_analysis = analytics_agent.analyze_vendor_performance(selected_vendor)
|
| 122 |
-
|
| 123 |
-
st.markdown(f"""
|
| 124 |
-
<div class="ai-insight">
|
| 125 |
-
<h4>π― AI Analysis: {selected_vendor}</h4>
|
| 126 |
-
<div style="white-space: pre-line;">{vendor_analysis}</div>
|
| 127 |
-
</div>
|
| 128 |
-
""", unsafe_allow_html=True)
|
| 129 |
-
|
| 130 |
-
# Anomaly insights with LLM
|
| 131 |
-
st.markdown("#### π¨ Intelligent Anomaly Analysis")
|
| 132 |
-
|
| 133 |
-
# Get anomalies from your existing detection logic
|
| 134 |
-
anomalies = [] # Your existing anomaly detection code here
|
| 135 |
-
|
| 136 |
-
with st.spinner('π AI is analyzing anomalies...'):
|
| 137 |
-
anomaly_insights = analytics_agent.generate_anomaly_insights(anomalies)
|
| 138 |
-
|
| 139 |
-
st.markdown(f"""
|
| 140 |
-
<div class="alert alert-warning">
|
| 141 |
-
<h4>π€ AI Anomaly Assessment</h4>
|
| 142 |
-
<div style="white-space: pre-line;">{anomaly_insights}</div>
|
| 143 |
-
</div>
|
| 144 |
-
""", unsafe_allow_html=True)
|
| 145 |
-
|
| 146 |
-
# Enhanced Risk Management with LLM
|
| 147 |
-
elif selected == "β οΈ Risk Management":
|
| 148 |
-
st.markdown("### π‘οΈ AI-Powered Risk Intelligence")
|
| 149 |
-
|
| 150 |
-
# ... existing risk metrics ...
|
| 151 |
-
|
| 152 |
-
# LLM-generated risk report
|
| 153 |
-
st.markdown("#### π Comprehensive Risk Assessment")
|
| 154 |
-
|
| 155 |
-
if st.button("π Generate AI Risk Report", type="primary"):
|
| 156 |
-
with st.spinner('π€ AI is generating comprehensive risk assessment...'):
|
| 157 |
-
risk_report = risk_agent.generate_risk_report()
|
| 158 |
-
|
| 159 |
-
st.markdown(f"""
|
| 160 |
-
<div class="ai-insight">
|
| 161 |
-
<h4>π‘οΈ Strategic Risk Analysis</h4>
|
| 162 |
-
<div style="white-space: pre-line;">{risk_report}</div>
|
| 163 |
-
</div>
|
| 164 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
import plotly.express as px
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
+
from plotly.subplots import make_subplots
|
| 7 |
from streamlit_option_menu import option_menu
|
|
|
|
|
|
|
| 8 |
import time
|
| 9 |
+
from faker import Faker
|
| 10 |
+
from datetime import datetime, timedelta
|
| 11 |
+
import random
|
| 12 |
+
import openai
|
| 13 |
+
import json
|
| 14 |
+
from typing import Dict, List, Any
|
| 15 |
|
| 16 |
+
# Page configuration
|
| 17 |
+
st.set_page_config(
|
| 18 |
+
page_title="SAP S/4HANA Agentic AI Procurement Analytics",
|
| 19 |
+
page_icon="π€",
|
| 20 |
+
layout="wide",
|
| 21 |
+
initial_sidebar_state="expanded"
|
| 22 |
+
)
|
| 23 |
|
| 24 |
+
# Custom CSS (same as before)
|
| 25 |
+
st.markdown("""
|
| 26 |
+
<style>
|
| 27 |
+
/* Main theme colors */
|
| 28 |
+
:root {
|
| 29 |
+
--primary-color: #0066cc;
|
| 30 |
+
--secondary-color: #f0f8ff;
|
| 31 |
+
--accent-color: #ff6b35;
|
| 32 |
+
--success-color: #28a745;
|
| 33 |
+
--warning-color: #ffc107;
|
| 34 |
+
--danger-color: #dc3545;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/* Hide Streamlit branding */
|
| 38 |
+
#MainMenu {visibility: hidden;}
|
| 39 |
+
footer {visibility: hidden;}
|
| 40 |
+
header {visibility: hidden;}
|
| 41 |
+
|
| 42 |
+
/* Custom header styling */
|
| 43 |
+
.main-header {
|
| 44 |
+
background: linear-gradient(90deg, #0066cc, #004c99);
|
| 45 |
+
padding: 1rem;
|
| 46 |
+
border-radius: 10px;
|
| 47 |
+
margin-bottom: 2rem;
|
| 48 |
+
color: white;
|
| 49 |
+
text-align: center;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* Metric cards styling */
|
| 53 |
+
.metric-card {
|
| 54 |
+
background: white;
|
| 55 |
+
padding: 1.5rem;
|
| 56 |
+
border-radius: 10px;
|
| 57 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 58 |
+
border-left: 4px solid var(--primary-color);
|
| 59 |
+
margin-bottom: 1rem;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
/* AI insights styling */
|
| 63 |
+
.ai-insight {
|
| 64 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 65 |
+
color: white;
|
| 66 |
+
padding: 1rem;
|
| 67 |
+
border-radius: 10px;
|
| 68 |
+
margin: 1rem 0;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/* Alert styling */
|
| 72 |
+
.alert {
|
| 73 |
+
padding: 1rem;
|
| 74 |
+
border-radius: 8px;
|
| 75 |
+
margin: 1rem 0;
|
| 76 |
+
border-left: 4px solid;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
.alert-success {
|
| 80 |
+
background-color: #d4edda;
|
| 81 |
+
border-color: var(--success-color);
|
| 82 |
+
color: #155724;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.alert-warning {
|
| 86 |
+
background-color: #fff3cd;
|
| 87 |
+
border-color: var(--warning-color);
|
| 88 |
+
color: #856404;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.alert-danger {
|
| 92 |
+
background-color: #f8d7da;
|
| 93 |
+
border-color: var(--danger-color);
|
| 94 |
+
color: #721c24;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/* Button styling */
|
| 98 |
+
.stButton > button {
|
| 99 |
+
background: linear-gradient(90deg, #0066cc, #004c99);
|
| 100 |
+
color: white;
|
| 101 |
+
border: none;
|
| 102 |
+
border-radius: 8px;
|
| 103 |
+
padding: 0.5rem 1rem;
|
| 104 |
+
font
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|