Skip to content

Commit c2ff686

Browse files
committed
initia
1 parent 8b6220b commit c2ff686

30 files changed

+1163
-47
lines changed

.github/workflows/deploy.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Code
13+
uses: actions/checkout@v2
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: '3.8'
19+
20+
- name: Install Dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements.txt
24+
25+
- name: Lint Code
26+
run: pylint app/**/*.py
27+
28+
- name: Run Unit Tests
29+
run: pytest tests/
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v1
33+
34+
- name: Build and Push Docker Image
35+
uses: docker/build-push-action@v2
36+
with:
37+
context: .
38+
tags: user/repository:latest
39+
push: true
40+
41+
deploy:
42+
needs: build
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Deploy to Kubernetes
46+
uses: azure/k8s-deploy@v1
47+
with:
48+
manifests: |
49+
deployment/kubernetes/deployment.yml
50+
deployment/kubernetes/service.yml

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,45 @@ For hyperparameter tuning, **Optuna** has been integrated to provide automated e
126126
- **🔍 Explainability**: SHAP and LIME explainability metrics are added to the evaluation process, providing insights into model behavior.
127127
- **📜 Logging**: Centralized logging using **ELK Stack** (Elasticsearch, Logstash, Kibana).
128128

129+
## 🚀 Cloud Deployment Instructions (AWS)
130+
131+
To deploy the LLM Alignment Assistant on **AWS**, you can utilize **Elastic Kubernetes Service (EKS)** or **AWS Sagemaker** for model training:
132+
133+
1. **AWS Elastic Kubernetes Service (EKS)**:
134+
- Create an EKS cluster using AWS CLI or the console.
135+
- Apply the Kubernetes deployment files:
136+
```bash
137+
kubectl apply -f deployment/kubernetes/deployment.yml
138+
kubectl apply -f deployment/kubernetes/service.yml
139+
```
140+
- Configure the **Horizontal Pod Autoscaler (HPA)** to ensure scalability:
141+
```bash
142+
kubectl apply -f deployment/kubernetes/hpa.yml
143+
```
144+
145+
2. **AWS Sagemaker for Model Training**:
146+
- Modify the `training/fine_tuning.py` to integrate with AWS Sagemaker.
147+
- Use the Sagemaker Python SDK to launch a training job:
148+
```python
149+
import sagemaker
150+
from sagemaker.pytorch import PyTorch
151+
152+
role = "arn:aws:iam::your-account-id:role/service-role/AmazonSageMaker-ExecutionRole-2023"
153+
154+
pytorch_estimator = PyTorch(
155+
entry_point='training/fine_tuning.py',
156+
role=role,
157+
instance_count=1,
158+
instance_type='ml.p2.xlarge',
159+
framework_version='1.8.0',
160+
py_version='py3'
161+
)
162+
163+
pytorch_estimator.fit({'training': 's3://your-bucket-name/training-data'})
164+
```
165+
- Ensure IAM roles and permissions are properly set for accessing **S3** and **Sagemaker**.
166+
167+
129168
## 🚀 Future Work
130169

131170
- **🌍 Multi-Language Support**: Expand the LLM's training to support multiple languages.

app/auth.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# User Authentication using Flask-Login
2+
3+
from flask import Flask, render_template, redirect, url_for, request, flash
4+
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user
5+
from werkzeug.security import generate_password_hash, check_password_hash
6+
7+
app = Flask(__name__)
8+
app.secret_key = 'secret-key'
9+
10+
# User session management setup
11+
login_manager = LoginManager()
12+
login_manager.init_app(app)
13+
login_manager.login_view = "login"
14+
15+
# Mock database for users
16+
users = {}
17+
18+
class User(UserMixin):
19+
def __init__(self, id, username, password):
20+
self.id = id
21+
self.username = username
22+
self.password_hash = generate_password_hash(password)
23+
24+
@login_manager.user_loader
25+
def load_user(user_id):
26+
return users.get(user_id)
27+
28+
@app.route('/register', methods=['GET', 'POST'])
29+
def register():
30+
if request.method == 'POST':
31+
username = request.form['username']
32+
password = request.form['password']
33+
user_id = len(users) + 1
34+
if username in [user.username for user in users.values()]:
35+
flash("Username already exists. Please choose a different one.")
36+
else:
37+
users[user_id] = User(user_id, username, password)
38+
flash("User registered successfully!")
39+
return redirect(url_for('login'))
40+
return render_template('register.html')
41+
42+
@app.route('/login', methods=['GET', 'POST'])
43+
def login():
44+
if request.method == 'POST':
45+
username = request.form['username']
46+
password = request.form['password']
47+
user = next((u for u in users.values() if u.username == username), None)
48+
if user and check_password_hash(user.password_hash, password):
49+
login_user(user)
50+
return redirect(url_for('dashboard'))
51+
else:
52+
flash("Invalid username or password.")
53+
return render_template('login.html')
54+
55+
@app.route('/dashboard')
56+
@login_required
57+
def dashboard():
58+
return render_template('dashboard.html')
59+
60+
@app.route('/logout')
61+
@login_required
62+
def logout():
63+
logout_user()
64+
return redirect(url_for('login'))
65+
66+
if __name__ == '__main__':
67+
app.run(debug=True)

app/feedback.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Flask route for handling feedback submission
2+
3+
from flask import Flask, request, jsonify, render_template
4+
import csv
5+
6+
app = Flask(__name__)
7+
8+
# Route to render feedback form
9+
@app.route('/feedback', methods=['GET'])
10+
def feedback():
11+
# You can dynamically pass the response to be rated in 'response' variable
12+
response = "Example response from LLM to be rated"
13+
return render_template('feedback.html', response=response)
14+
15+
# Route to handle feedback submission
16+
@app.route('/submit-feedback', methods=['POST'])
17+
def submit_feedback():
18+
rating = request.form['rating']
19+
comments = request.form['comments']
20+
model_response = request.form['model-response']
21+
22+
# Save feedback to a CSV file
23+
with open('feedback.csv', mode='a') as feedback_file:
24+
feedback_writer = csv.writer(feedback_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
25+
feedback_writer.writerow([model_response, rating, comments])
26+
27+
return jsonify(status='success', message='Thank you for your feedback!')
28+
29+
if __name__ == "__main__":
30+
app.run(debug=True)

app/static/app.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
console.log('App JS');
1+
// UI Enhancements - Adding Animations, Dark Mode Toggle, and Tooltips
2+
3+
document.addEventListener('DOMContentLoaded', function() {
4+
// Dark Mode Toggle
5+
const darkModeToggle = document.getElementById('dark-mode-toggle');
6+
const body = document.body;
7+
8+
darkModeToggle.addEventListener('click', () => {
9+
body.classList.toggle('dark-mode');
10+
if (body.classList.contains('dark-mode')) {
11+
localStorage.setItem('theme', 'dark');
12+
} else {
13+
localStorage.setItem('theme', 'light');
14+
}
15+
});
16+
17+
// Persist Dark Mode Setting
18+
if (localStorage.getItem('theme') === 'dark') {
19+
body.classList.add('dark-mode');
20+
}
21+
22+
// Tooltip Initialization
23+
const tooltips = document.querySelectorAll('.tooltip');
24+
tooltips.forEach(tooltip => {
25+
tooltip.addEventListener('mouseover', function() {
26+
const tooltipText = document.createElement('span');
27+
tooltipText.className = 'tooltip-text';
28+
tooltipText.innerText = this.getAttribute('data-tooltip');
29+
this.appendChild(tooltipText);
30+
});
31+
tooltip.addEventListener('mouseout', function() {
32+
const tooltipText = this.querySelector('.tooltip-text');
33+
if (tooltipText) this.removeChild(tooltipText);
34+
});
35+
});
36+
37+
// GSAP Animations for Elements
38+
gsap.from('.card', {
39+
duration: 1,
40+
y: 50,
41+
opacity: 0,
42+
stagger: 0.2,
43+
ease: 'power2.out'
44+
});
45+
});
46+

app/static/chart.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Interactive Chart.js Visualizations
2+
3+
document.addEventListener('DOMContentLoaded', function() {
4+
const ctx = document.getElementById('modelPerformanceChart').getContext('2d');
5+
const modelPerformanceChart = new Chart(ctx, {
6+
type: 'line',
7+
data: {
8+
labels: ['Epoch 1', 'Epoch 2', 'Epoch 3', 'Epoch 4', 'Epoch 5'],
9+
datasets: [{
10+
label: 'Training Loss',
11+
data: [0.8, 0.6, 0.4, 0.3, 0.2],
12+
borderColor: 'rgba(75, 192, 192, 1)',
13+
backgroundColor: 'rgba(75, 192, 192, 0.2)',
14+
fill: true,
15+
tension: 0.4
16+
}, {
17+
label: 'Validation Loss',
18+
data: [0.9, 0.7, 0.5, 0.4, 0.3],
19+
borderColor: 'rgba(255, 99, 132, 1)',
20+
backgroundColor: 'rgba(255, 99, 132, 0.2)',
21+
fill: true,
22+
tension: 0.4
23+
}]
24+
},
25+
options: {
26+
responsive: true,
27+
plugins: {
28+
legend: {
29+
position: 'top',
30+
},
31+
tooltip: {
32+
mode: 'index',
33+
intersect: false,
34+
}
35+
},
36+
interaction: {
37+
mode: 'nearest',
38+
axis: 'x',
39+
intersect: false
40+
},
41+
scales: {
42+
x: {
43+
display: true,
44+
title: {
45+
display: true,
46+
text: 'Epoch'
47+
}
48+
},
49+
y: {
50+
display: true,
51+
title: {
52+
display: true,
53+
text: 'Loss'
54+
}
55+
}
56+
}
57+
}
58+
});
59+
});
60+

app/static/styles.css

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
body { font-family: Arial; }
1+
/* Dark Mode Styles */
2+
body.dark-mode {
3+
background-color: #121212;
4+
color: #ffffff;
5+
}
6+
7+
button#dark-mode-toggle {
8+
background-color: #333;
9+
color: #fff;
10+
border: none;
11+
padding: 10px;
12+
cursor: pointer;
13+
border-radius: 5px;
14+
}
15+
16+
button#dark-mode-toggle:hover {
17+
background-color: #555;
18+
}
19+
20+
/* Tooltip Styles */
21+
.tooltip {
22+
position: relative;
23+
cursor: pointer;
24+
}
25+
26+
.tooltip .tooltip-text {
27+
position: absolute;
28+
bottom: 125%;
29+
left: 50%;
30+
transform: translateX(-50%);
31+
background-color: #333;
32+
color: #fff;
33+
padding: 5px;
34+
border-radius: 4px;
35+
white-space: nowrap;
36+
opacity: 0;
37+
transition: opacity 0.3s;
38+
}
39+
40+
.tooltip:hover .tooltip-text {
41+
opacity: 1;
42+
}
43+
44+
/* GSAP Animation Styles */
45+
.card {
46+
background: #f8f8f8;
47+
padding: 20px;
48+
margin: 20px;
49+
border-radius: 10px;
50+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
51+
}
52+

0 commit comments

Comments
 (0)