Introduction
As the EU AI Act's Article 50 transparency rules come into force, organizations deploying AI systems must now ensure their applications disclose when users are interacting with AI. This tutorial will show you how to implement AI transparency features in a Python-based web application using Flask, helping you comply with these new regulations. We'll build a simple chatbot interface that clearly indicates AI interaction to users.
Prerequisites
- Python 3.8 or higher installed
- Basic understanding of Flask web development
- Knowledge of HTML/CSS and JavaScript
- Basic understanding of AI/ML concepts
Step-by-Step Instructions
1. Set Up Your Development Environment
First, create a new Python virtual environment and install the required packages. This ensures you have a clean, isolated environment for our project.
python -m venv ai_transparency_env
source ai_transparency_env/bin/activate # On Windows: ai_transparency_env\Scripts\activate
pip install flask openai
2. Create the Main Flask Application
Let's create the main application structure. This will include routes for serving the web interface and handling AI interactions.
from flask import Flask, render_template, request, jsonify
import os
app = Flask(__name__)
# For demonstration purposes, we'll use a simple mock AI response
# In production, you'd integrate with actual AI services like OpenAI
@app.route('/')
def index():
return render_template('index.html')
@app.route('/chat', methods=['POST'])
def chat():
user_message = request.json['message']
# Simulate AI processing
ai_response = f"AI Response to: {user_message}"
return jsonify({
'response': ai_response,
'is_ai': True,
'timestamp': '2023-06-15T10:00:00Z'
})
if __name__ == '__main__':
app.run(debug=True)
3. Create the HTML Template
Create a templates folder and add an index.html file. This will serve as our user interface with clear AI transparency indicators.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Transparency Demo</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.ai-indicator { background-color: #e3f2fd; border-left: 4px solid #2196f3; padding: 10px; margin: 10px 0; }
.user-message { background-color: #f5f5f5; padding: 10px; margin: 10px 0; }
.ai-message { background-color: #e8f5e9; padding: 10px; margin: 10px 0; }
.chat-container { max-width: 600px; margin: 0 auto; }
button { background-color: #4caf50; color: white; padding: 10px 20px; border: none; cursor: pointer; }
button:hover { background-color: #45a049; }
</style>
</head>
<body>
<div class="chat-container">
<h1>AI Transparency Chat</h1>
<div id="chat-messages"></div>
<input type="text" id="user-input" placeholder="Type your message...">
<button onclick="sendMessage()">Send</button>
<div class="ai-indicator">
<p><strong>AI Transparency Notice:</strong> This conversation is being conducted with an AI system. All responses are generated by artificial intelligence.</p>
</div>
</div>
<script>
function sendMessage() {
const input = document.getElementById('user-input');
const message = input.value;
if (message.trim() === '') return;
// Display user message
addMessage(message, 'user');
input.value = '';
// Send to backend
fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: message })
})
.then(response => response.json())
.then(data => {
addMessage(data.response, 'ai');
});
}
function addMessage(message, sender) {
const chatMessages = document.getElementById('chat-messages');
const messageDiv = document.createElement('div');
if (sender === 'user') {
messageDiv.className = 'user-message';
messageDiv.textContent = message;
} else {
messageDiv.className = 'ai-message';
messageDiv.innerHTML = `AI Response: ${message}`;
}
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
</script>
</body>
</html>
4. Implement AI Transparency Features
Now we'll enhance our application to include clear AI transparency indicators. According to Article 50, users must be informed when they're interacting with AI.
from flask import Flask, render_template, request, jsonify
import datetime
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/chat', methods=['POST'])
def chat():
user_message = request.json['message']
# Simulate AI processing with transparency indicators
ai_response = f"AI Response to: {user_message}"
# Include transparency metadata
response_data = {
'response': ai_response,
'is_ai': True,
'timestamp': datetime.datetime.now().isoformat(),
'ai_system': 'Demo AI Assistant v1.0',
'transparency_notice': 'This response was generated by an artificial intelligence system.',
'disclaimer': 'This AI system may produce inaccurate information. Please verify important facts.'
}
return jsonify(response_data)
if __name__ == '__main__':
app.run(debug=True)
5. Enhance the Frontend with Transparency Elements
Update the HTML to display additional transparency information in a user-friendly way.
<div class="ai-indicator">
<p><strong>AI Transparency Notice:</strong> This conversation is being conducted with an AI system. All responses are generated by artificial intelligence.</p>
<p><strong>AI System:</strong> Demo AI Assistant v1.0</p>
<p><strong>Disclaimer:</strong> This AI system may produce inaccurate information. Please verify important facts.</p>
</div>
6. Test Your Implementation
Run your Flask application and test the transparency features:
python app.py
Visit http://localhost:5000 in your browser. You should see:
- A clear AI transparency notice at the top of the chat interface
- User messages displayed in one style
- AI responses displayed with clear AI indicators
- Transparency metadata in the AI responses
Summary
This tutorial demonstrated how to implement AI transparency features in a web application, preparing you for compliance with EU AI Act Article 50. The key elements include:
- Clear AI disclosure in user interfaces
- Transparency metadata in AI responses
- User-friendly design that emphasizes AI interaction
- Compliance-ready structure for future AI system integration
Remember, as AI systems become more sophisticated, transparency requirements will continue to evolve. This foundation provides a starting point for building more complex, compliant AI applications.



