Skip to content

Commit dd7957d

Browse files
committed
CICD run - 11
1 parent 70a71b3 commit dd7957d

6 files changed

Lines changed: 117 additions & 200 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,29 @@ jobs:
4949
if: success()
5050
env:
5151
CAPSTONE_TEST: ${{ secrets.CAPSTONE_TEST }}
52-
run: python -m unittest tests/test_fastapi_app.py
52+
run: python -m unittest tests/test_fastapi_app.py
53+
54+
# - name: Login to AWS ECR
55+
# if: success()
56+
# run: |
57+
# aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
58+
# aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
59+
# aws configure set region ${{ secrets.AWS_REGION }}
60+
# aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
61+
62+
# - name: Build Docker image
63+
# run: |
64+
# docker build -t ${{ secrets.ECR_REPOSITORY }}:latest .
65+
66+
# - name: Tag Docker image
67+
# run: |
68+
# docker tag ${{ secrets.ECR_REPOSITORY }}:latest \
69+
# ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:latest
70+
71+
72+
# - name: Check Docker Authentication
73+
# run: docker info
74+
75+
# - name: Push Docker image to ECR
76+
# run: |
77+
# docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:latest

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3.10-slim
2+
3+
WORKDIR /app
4+
5+
COPY fastapi_app/ /app/
6+
7+
COPY models/vectorizer.pkl /app/models/vectorizer.pkl
8+
9+
RUN pip install -r requirements.txt
10+
11+
RUN python -m nltk.downloader stopwords wordnet
12+
13+
EXPOSE 5000
14+
15+
#local
16+
# CMD ["python", "app.py"]
17+
18+
#Prod
19+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--timeout", "120", "app:app"]

fastapi_app/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
warnings.simplefilter("ignore", UserWarning)
1717
warnings.filterwarnings("ignore")
1818

19+
from dotenv import load_dotenv
20+
21+
load_dotenv()
22+
1923
def lemmatization(text):
2024
"""Lemmatize the text."""
2125
lemmatizer = WordNetLemmatizer()

fastapi_app/templates/index.html

Lines changed: 66 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -3,217 +3,86 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Sentiment Analysis AI</title>
7-
<!-- Tailwind CSS CDN -->
8-
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
9-
<!-- Custom Tailwind Configuration -->
10-
<script>
11-
tailwind.config = {
12-
theme: {
13-
extend: {
14-
colors: {
15-
primary: '#3b82f6',
16-
secondary: '#8b5cf6',
17-
}
18-
}
19-
}
6+
<title>Sentiment Analysis</title>
7+
<script src="https://cdn.tailwindcss.com"></script>
8+
<style>
9+
@keyframes fadeIn {
10+
from { opacity: 0; transform: translateY(10px); }
11+
to { opacity: 1; transform: translateY(0); }
12+
}
13+
.fade-in {
14+
animation: fadeIn 0.5s ease-out forwards;
15+
}
16+
body {
17+
font-family: 'Inter', sans-serif;
2018
}
21-
</script>
22-
<!-- Font Awesome for Icons -->
23-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
19+
.glass-card {
20+
background: rgba(255, 255, 255, 0.05);
21+
backdrop-filter: blur(10px);
22+
border: 1px solid rgba(255, 255, 255, 0.1);
23+
}
24+
.btn-gradient {
25+
background-image: linear-gradient(to right, #4f46e5, #c026d3);
26+
}
27+
</style>
28+
<link rel="preconnect" href="https://fonts.googleapis.com">
29+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
30+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
2431
</head>
25-
<body class="bg-gradient-to-br from-blue-50 via-white to-purple-50 min-h-screen">
26-
<!-- Header -->
27-
<header class="bg-white shadow-md">
28-
<div class="container mx-auto px-4 py-6">
29-
<div class="flex items-center justify-between">
30-
<div class="flex items-center space-x-3">
31-
<div class="bg-gradient-to-r from-blue-500 to-purple-600 p-3 rounded-lg">
32-
<i class="fas fa-brain text-white text-2xl"></i>
33-
</div>
34-
<div>
35-
<h1 class="text-3xl font-bold bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
36-
Sentiment Analysis AI
37-
</h1>
38-
<p class="text-sm text-gray-600">Powered by Machine Learning</p>
39-
</div>
40-
</div>
32+
<body class="bg-gray-900 text-white">
33+
<div class="min-h-screen flex flex-col items-center justify-center p-4">
34+
<div class="w-full max-w-2xl">
35+
<div class="text-center mb-8 fade-in">
36+
<h1 class="text-4xl md:text-5xl font-bold tracking-tight">Sentiment Analyzer</h1>
37+
<p class="text-gray-400 mt-3 text-lg">Instantly analyze the sentiment of your text.</p>
4138
</div>
42-
</div>
43-
</header>
4439

45-
<!-- Main Content -->
46-
<main class="container mx-auto px-4 py-12">
47-
<div class="max-w-4xl mx-auto">
48-
<!-- Info Cards -->
49-
<div class="grid md:grid-cols-3 gap-6 mb-12">
50-
<div class="bg-white rounded-xl shadow-lg p-6 hover:shadow-xl transition-shadow">
51-
<div class="flex items-center justify-center w-12 h-12 bg-blue-100 rounded-lg mb-4">
52-
<i class="fas fa-robot text-blue-600 text-xl"></i>
53-
</div>
54-
<h3 class="text-lg font-semibold text-gray-800 mb-2">AI-Powered</h3>
55-
<p class="text-gray-600 text-sm">Advanced NLP model for accurate sentiment detection</p>
56-
</div>
57-
<div class="bg-white rounded-xl shadow-lg p-6 hover:shadow-xl transition-shadow">
58-
<div class="flex items-center justify-center w-12 h-12 bg-purple-100 rounded-lg mb-4">
59-
<i class="fas fa-bolt text-purple-600 text-xl"></i>
40+
<div class="glass-card rounded-2xl shadow-2xl p-8 fade-in" style="animation-delay: 0.2s;">
41+
<form action="/predict" method="POST">
42+
<div class="mb-6">
43+
<label for="text" class="sr-only">Your text</label>
44+
<textarea
45+
id="text"
46+
name="text"
47+
rows="6"
48+
required
49+
class="w-full bg-gray-800 border-2 border-gray-700 rounded-lg px-4 py-3 text-base text-white placeholder-gray-500 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all duration-300 resize-none"
50+
placeholder="Enter text to analyze..."
51+
></textarea>
6052
</div>
61-
<h3 class="text-lg font-semibold text-gray-800 mb-2">Lightning Fast</h3>
62-
<p class="text-gray-600 text-sm">Get instant sentiment analysis in milliseconds</p>
63-
</div>
64-
<div class="bg-white rounded-xl shadow-lg p-6 hover:shadow-xl transition-shadow">
65-
<div class="flex items-center justify-center w-12 h-12 bg-green-100 rounded-lg mb-4">
66-
<i class="fas fa-shield-alt text-green-600 text-xl"></i>
67-
</div>
68-
<h3 class="text-lg font-semibold text-gray-800 mb-2">Secure & Private</h3>
69-
<p class="text-gray-600 text-sm">Your data is processed securely and never stored</p>
70-
</div>
71-
</div>
7253

73-
<!-- Main Analysis Card -->
74-
<div class="bg-white rounded-2xl shadow-2xl overflow-hidden">
75-
<div class="bg-gradient-to-r from-blue-600 to-purple-600 px-8 py-6">
76-
<h2 class="text-2xl font-bold text-white flex items-center">
77-
<i class="fas fa-comment-dots mr-3"></i>
78-
Analyze Your Text
79-
</h2>
80-
<p class="text-blue-100 mt-2">Enter your text below to analyze its sentiment</p>
81-
</div>
54+
<button
55+
type="submit"
56+
class="w-full btn-gradient text-white font-semibold py-3 rounded-lg transition-transform transform hover:scale-105 focus:outline-none focus:ring-4 focus:ring-purple-500 focus:ring-opacity-50"
57+
>
58+
Analyze Sentiment
59+
</button>
60+
</form>
8261

83-
<div class="p-8">
84-
<form action="/predict" method="POST" class="space-y-6">
62+
{% if result is not none %}
63+
<div class="mt-8 pt-6 border-t border-gray-700 fade-in" style="animation-delay: 0.4s;">
64+
{% if result == 1 %}
65+
<div class="flex items-start space-x-4 bg-green-500/10 border border-green-500/30 text-green-300 px-5 py-4 rounded-lg">
66+
<svg class="w-6 h-6 flex-shrink-0 mt-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.828 14.828a4 4 0 01-5.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
8567
<div>
86-
<label for="text" class="block text-sm font-semibold text-gray-700 mb-3">
87-
<i class="fas fa-pencil-alt mr-2 text-blue-600"></i>Your Text
88-
</label>
89-
<textarea
90-
id="text"
91-
name="text"
92-
rows="6"
93-
required
94-
class="w-full px-4 py-3 border-2 border-gray-300 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all resize-none text-gray-800 placeholder-gray-400"
95-
placeholder="Type or paste your text here... (e.g., 'I absolutely loved this movie! It was fantastic!')"></textarea>
96-
<p class="mt-2 text-xs text-gray-500">
97-
<i class="fas fa-info-circle mr-1"></i>
98-
Tip: The more context you provide, the better the analysis
99-
</p>
100-
</div>
101-
102-
<button
103-
type="submit"
104-
class="w-full bg-gradient-to-r from-blue-600 to-purple-600 text-white font-semibold py-4 px-6 rounded-xl hover:from-blue-700 hover:to-purple-700 transform hover:scale-[1.02] transition-all duration-200 shadow-lg hover:shadow-xl flex items-center justify-center space-x-2">
105-
<i class="fas fa-chart-line"></i>
106-
<span>Analyze Sentiment</span>
107-
</button>
108-
</form>
109-
110-
<!-- Result Display -->
111-
{% if result is not none %}
112-
<div class="mt-8 animate-fade-in">
113-
<div class="border-t-2 border-gray-200 pt-6">
114-
<h3 class="text-lg font-semibold text-gray-800 mb-4 flex items-center">
115-
<i class="fas fa-poll mr-2 text-gray-700"></i>Analysis Result
116-
</h3>
117-
118-
{% if result == 1 %}
119-
<!-- Positive Result -->
120-
<div class="bg-gradient-to-r from-green-50 to-emerald-50 border-2 border-green-300 rounded-xl p-6">
121-
<div class="flex items-center justify-between">
122-
<div class="flex items-center space-x-4">
123-
<div class="bg-green-500 rounded-full p-4">
124-
<i class="fas fa-smile-beam text-white text-3xl"></i>
125-
</div>
126-
<div>
127-
<h4 class="text-2xl font-bold text-green-700">Positive Sentiment</h4>
128-
<p class="text-green-600 mt-1">This text expresses positive emotions</p>
129-
</div>
130-
</div>
131-
<div class="hidden md:block">
132-
<div class="text-6xl">😊</div>
133-
</div>
134-
</div>
135-
</div>
136-
{% else %}
137-
<!-- Negative Result -->
138-
<div class="bg-gradient-to-r from-red-50 to-pink-50 border-2 border-red-300 rounded-xl p-6">
139-
<div class="flex items-center justify-between">
140-
<div class="flex items-center space-x-4">
141-
<div class="bg-red-500 rounded-full p-4">
142-
<i class="fas fa-frown text-white text-3xl"></i>
143-
</div>
144-
<div>
145-
<h4 class="text-2xl font-bold text-red-700">Negative Sentiment</h4>
146-
<p class="text-red-600 mt-1">This text expresses negative emotions</p>
147-
</div>
148-
</div>
149-
<div class="hidden md:block">
150-
<div class="text-6xl">😞</div>
151-
</div>
152-
</div>
153-
</div>
154-
{% endif %}
68+
<h4 class="text-lg font-semibold">Positive Sentiment</h4>
69+
<p class="text-sm text-green-300/80">The analysis indicates a positive tone.</p>
15570
</div>
15671
</div>
157-
{% endif %}
158-
</div>
159-
</div>
160-
161-
<!-- How It Works Section -->
162-
<div class="mt-12 bg-white rounded-xl shadow-lg p-8">
163-
<h3 class="text-2xl font-bold text-gray-800 mb-6 text-center">
164-
<i class="fas fa-lightbulb text-yellow-500 mr-2"></i>How It Works
165-
</h3>
166-
<div class="grid md:grid-cols-4 gap-6">
167-
<div class="text-center">
168-
<div class="bg-blue-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
169-
<span class="text-2xl font-bold text-blue-600">1</span>
170-
</div>
171-
<p class="text-sm text-gray-600">Enter your text</p>
172-
</div>
173-
<div class="text-center">
174-
<div class="bg-purple-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
175-
<span class="text-2xl font-bold text-purple-600">2</span>
176-
</div>
177-
<p class="text-sm text-gray-600">AI processes text</p>
178-
</div>
179-
<div class="text-center">
180-
<div class="bg-pink-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
181-
<span class="text-2xl font-bold text-pink-600">3</span>
182-
</div>
183-
<p class="text-sm text-gray-600">Analyze sentiment</p>
184-
</div>
185-
<div class="text-center">
186-
<div class="bg-green-100 rounded-full w-16 h-16 flex items-center justify-center mx-auto mb-3">
187-
<span class="text-2xl font-bold text-green-600">4</span>
72+
{% else %}
73+
<div class="flex items-start space-x-4 bg-red-500/10 border border-red-500/30 text-red-300 px-5 py-4 rounded-lg">
74+
<svg class="w-6 h-6 flex-shrink-0 mt-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
75+
<div>
76+
<h4 class="text-lg font-semibold">Negative Sentiment</h4>
77+
<p class="text-sm text-red-300/80">The analysis indicates a negative tone.</p>
18878
</div>
189-
<p class="text-sm text-gray-600">Get instant results</p>
19079
</div>
80+
{% endif %}
19181
</div>
82+
{% endif %}
19283
</div>
84+
19385
</div>
194-
</main>
195-
196-
<!-- Footer -->
197-
<footer class="bg-gray-900 text-white mt-20">
198-
<div class="container mx-auto px-4 py-8">
199-
<div class="text-center">
200-
<p class="text-gray-400">
201-
<i class="fas fa-code mr-2"></i>Built with FastAPI & MLflow |
202-
<i class="fas fa-brain ml-2 mr-2"></i>Powered by Advanced NLP
203-
</p>
204-
</div>
205-
</div>
206-
</footer>
207-
208-
<!-- Add fade-in animation -->
209-
<style>
210-
@keyframes fadeIn {
211-
from { opacity: 0; transform: translateY(10px); }
212-
to { opacity: 1; transform: translateY(0); }
213-
}
214-
.animate-fade-in {
215-
animation: fadeIn 0.5s ease-out;
216-
}
217-
</style>
86+
</div>
21887
</body>
21988
</html>

params.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ data_ingestion:
33
test_size: 0.25
44

55
feature_engineering:
6-
max_features: 50
6+
max_features: 1000

sentiment_classification/data/data_ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def main():
8383
test_size = params['data_ingestion']['test_size']
8484
# test_size = 0.2
8585

86-
df = load_data(data_url='https://raw.githubusercontent.com/CodeBy-HP/Sentiment-Classification-Mlflow-DVC/refs/heads/main/notebooks/data.csv')
86+
df = load_data(data_url='https://raw.githubusercontent.com/CodeBy-HP/Sentiment-Classification-Mlflow-DVC/refs/heads/main/notebooks/IMDB.csv')
8787

8888
# s3 = s3_connection.s3_operations(bucketname,accesskey,secretkey)
8989
# df = s3.fetch_file_from_s3("data.csv")

0 commit comments

Comments
 (0)