-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
323 lines (283 loc) · 9.65 KB
/
app.py
1
2
3
4
5
6
7
8
9
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
from flask import Flask, render_template_string, request
import joblib
app = Flask(__name__)
# Loading the trained model here
model = joblib.load('credit_card_model.pkl')
@app.route('/', methods=['GET', 'POST'])
def predict():
prediction = None
if request.method == 'POST':
features = [float(request.form[f'feature{i}']) for i in range(1, 30)]
pred = model.predict([features])[0]
prediction = "Fraudulent Transaction" if pred == 1 else "Normal Transaction"
return render_template_string('''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Credit Card Fraud Detection</title>
<style>
/* General Settings */
body {
font-family: 'Arial', sans-serif;
background-color: #1b1b1b;
color: #f5f5f5;
margin: 0;
padding: 0;
line-height: 1.6;
}
/* Navbar */
.navbar {
background-color: #333;
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.navbar h1 {
color: #f5f5f5;
margin: 0;
}
.navbar ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
}
.navbar ul li {
margin-left: 20px;
}
.navbar ul li a {
color: #f5f5f5;
text-decoration: none;
padding: 5px 10px;
transition: background-color 0.3s ease-in-out;
}
.navbar ul li a:hover {
background-color: #555;
border-radius: 5px;
}
/* Container */
.container {
max-width: 1200px;
margin: 30px auto;
padding: 20px;
background-color: #2b2b2b;
border-radius: 10px;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.5);
}
/* Forms */
form {
margin: 0 auto;
padding: 1rem;
}
form label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
form input[type="text"],
form input[type="number"],
form input[type="email"],
form select {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #333;
color: #f5f5f5;
}
form input[type="submit"] {
background-color: #f39c12;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
}
form input[type="submit"]:hover {
background-color: #e67e22;
}
/* Footer */
.footer {
text-align: center;
padding: 2px;
background-color: #333;
color: #f5f5f5;
position: fixed;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div class="navbar">
<h1>                       Credit Card Fraud Detection</h1>
<img src="{{ url_for('static', filename='img2.jpg') }}" height="60" width="190" >
<ul>
<li><a href="/">Home</a></li>
<li><a href="/connect">Connect</a></li>
</ul>
</div>
<div class="container">
<h2>Enter Transaction Data</h2>
<form action="/" method="post">
{% for i in range(1, 30) %}
<label for="feature{{ i }}">Feature {{ i }}:</label>
<input type="text" id="feature{{ i }}" name="feature{{ i }}">
{% endfor %}
<input type="submit" value="Predict">
</form>
{% if prediction %}
<h2>Prediction Result:</h2>
<p>{{ prediction }}</p>
{% endif %}
</div>
<div class="footer">
<p>© 2024 Credit Card Fraud Detection. All Rights Reserved.</p>
</div>
</body>
</html>
''', prediction=prediction)
@app.route('/connect', methods=['GET', 'POST'])
def connect():
alert_script = """
<script>
function showAlert() {
alert("Thank you for reaching out! We will get back to you soon.");
}
</script>
"""
return render_template_string(f'''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connect with Us</title>
<style>
/* General Settings */
body {{
font-family: 'Arial', sans-serif;
background-color: #1b1b1b;
color: #f5f5f5;
margin: 0;
padding: 0;
line-height: 1.6;
}}
/* Navbar */
.navbar {{
background-color: #333;
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}}
.navbar h1 {{
color: #f5f5f5;
margin: 0;
}}
.navbar ul {{
list-style: none;
padding: 0;
margin: 0;
display: flex;
}}
.navbar ul li {{
margin-left: 20px;
}}
.navbar ul li a {{
color: #f5f5f5;
text-decoration: none;
padding: 5px 10px;
transition: background-color 0.3s ease-in-out;
}}
.navbar ul li a:hover {{
background-color: #555;
border-radius: 5px;
}}
/* Container */
.container {{
max-width: 1200px;
margin: 30px auto;
padding: 20px;
background-color: #2b2b2b;
border-radius: 10px;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.5);
}}
/* Form */
form {{
display: flex;
flex-direction: column;
}}
form label {{
margin-top: 10px;
}}
form input[type="text"],
form input[type="email"],
form textarea {{
padding: 10px;
margin-top: 5px;
background-color: #333;
color: #f5f5f5;
border: 1px solid #555;
border-radius: 5px;
}}
form input[type="submit"] {{
margin-top: 20px;
padding: 10px;
background-color: #555;
color: #f5f5f5;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
}}
form input[type="submit"]:hover {{
background-color: #777;
}}
/* Footer */
.footer {{
text-align: center;
padding: 3px;
background-color: #333;
color: #f5f5f5;
position: fixed;
bottom: 0;
width: 100%;
}}
</style>
{alert_script}
</head>
<body>
<div class="navbar">
<h1>Credit Card Fraud Detection</h1>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/connect">Connect</a></li>
</ul>
</div>
<div class="container">
<h2>Connect with Us</h2>
<p>If you have any questions, feedback, or just want to get in touch, feel free to reach out!</p>
<form onsubmit="showAlert()">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required>
<label for="email">Your Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" required>
<label for="message">Your Message:</label>
<textarea id="message" name="message" rows="4" placeholder="Enter your message" required></textarea>
<input type="submit" value="Send Message">
</form>
</div>
<div class="footer">
<p>© 2024 Credit Card Fraud Detection. All Rights Reserved.</p>
</div>
</body>
</html>
''')
if __name__ == '__main__':
app.run(debug=True)