Using AI, generate an SAP ECC control given a risk.
To upload files, please first save the app
import streamlit as st
import openai
st.title("SAP ECC Control Generator")
# Initialize session state for chat history if it doesn't exist
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Initialize OpenAI client
client = openai.OpenAI(
base_url="https://api.openai.com/v1",
api_key=st.secrets["OPENAI_API_KEY"],
)
# Function to generate control using OpenAI
def generate_control(risk_description):
prompt = f"""Given the following risk in SAP ECC, generate a detailed control:
Risk: {risk_description}
Please provide a control that includes:
1. Control description
2. Control type (Preventive/Detective)
3. Control frequency
4. Control owner
5. SAP transaction codes involved
6. Specific configuration settings if applicable
"""
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are an SAP security and controls expert."},
{"role": "user", "content": prompt}
],
temperature=0.7,
max_tokens=500
)
return response.choices[0].message.content
except Exception as e:
return f"Error generating control: {str(e)}"
# Create the input form
with st.form("risk_input_form"):
risk_description = st.text_area("Enter the risk description:", height=100)
submit_button = st.form_submit_button("Generate Control")
if submit_button and risk_description:
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": f"**Risk Description:**\n{risk_description}"})
# Generate control and display it
with st.chat_message("assistant"):
control_response = generate_control(risk_description)
st.markdown(control_response)
# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": control_response})
st.sidebar.markdown("""
## About
This app uses AI to generate SAP ECC controls based on risk descriptions. The generated controls include:
- Control description
- Control type
- Control frequency
- Control owner
- SAP transaction codes
- Configuration settings
## How to use
1. Enter a risk description in the text area
2. Click 'Generate Control'
3. Review the AI-generated control recommendation
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?