GAlbayrak commited on
Commit
76c0b7a
·
verified ·
1 Parent(s): 39a2303

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -73
app.py CHANGED
@@ -1,84 +1,84 @@
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
4
- import os
5
- from flask import Flask, render_template, jsonify
6
- import random
7
-
8
- # Dizinlerin oluşturulması
9
- os.makedirs('cyber_security_platform/app/templates', exist_ok=True)
10
-
11
- # HTML dosyasının oluşturulması ve içeriğin yazılması
12
- <!DOCTYPE html>
13
- <html lang="en">
14
- <head>
15
- <meta charset="UTF-8">
16
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
17
- <title>Cyber Security Platform</title>
18
- <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
19
- </head>
20
- <body>
21
- <header>
22
- <h1>Cyber Security AI Simulation</h1>
23
- <nav>
24
- <ul>
25
- <li><a href="#about">About</a></li>
26
- <li><a href="#features">Features</a></li>
27
- <li><a href="#contact">Contact</a></li>
28
- </ul>
29
- </nav>
30
- </header>
31
- <main>
32
- <section id="about">
33
- <h2>About the Simulation</h2>
34
- <p>Welcome to the Cyber Security AI Simulation. This platform is designed to help you learn and practice cyber security techniques using the power of artificial intelligence.</p>
35
- </section>
36
- <section id="features">
37
- <h2>Features</h2>
38
- <ul>
39
- <li>Real-time threat detection</li>
40
- <li>Interactive learning modules</li>
41
- <li>AI-driven security analysis</li>
42
- </ul>
43
- </section>
44
- <section id="start-simulation">
45
- <h2>Start the Simulation</h2>
46
- <button onclick="startSimulation()">Start Simulation</button>
47
- <div id="simulation-result"></div>
48
- </section>
49
- </main>
50
- <footer>
51
- <p>&copy; 2024 Cyber Security AI Simulation. All rights reserved.</p>
52
- </footer>
53
- <script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
54
- </body>
55
- </html>
56
-
57
- with open('cyber_security_platform/app/templates/index.html', 'w') as file:
58
- file.write(html_content)
59
-
60
- # Flask uygulaması için gerekli kodlar
61
  app = Flask(__name__)
62
 
63
- # Tehdit türlerini belirleme işlevi
64
- def generate_threat():
65
- threats = [
66
- "DDoS Attack",
67
- "Data Breach",
68
- "Malware Infection",
69
- "Phishing Attempt",
70
- "SQL Injection"
71
- ]
72
- return random.choice(threats)
73
 
74
  @app.route('/')
75
- def home():
76
  return render_template('index.html')
77
 
78
- @app.route('/start_simulation')
79
- def start_simulation():
80
- detected_threat = generate_threat()
81
- return jsonify(result=detected_threat)
 
 
 
 
 
 
 
82
 
83
  if __name__ == '__main__':
84
- app.run(debug=True, host='0.0.0.0')
 
 
 
 
 
 
 
 
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
4
+ # In[1]:
5
+
6
+
7
+ import pandas as pd
8
+ import numpy as np
9
+
10
+ # Örnek veri seti oluşturma
11
+ np.random.seed(42) # Tekrarlanabilir sonuçlar için
12
+
13
+ # Özellikler ve etiketler oluşturma
14
+ data = pd.DataFrame({
15
+ 'feature1': np.random.rand(100),
16
+ 'feature2': np.random.rand(100),
17
+ 'target': np.random.randint(0, 2, 100)
18
+ })
19
+
20
+ # Veri setini kaydetme
21
+ data.to_csv('data.csv', index=False)
22
+ print("Örnek veri seti 'data.csv' dosyasına kaydedildi.")
23
+
24
+
25
+ # In[2]:
26
+
27
+
28
+ from sklearn.ensemble import RandomForestClassifier
29
+ import pickle
30
+ import numpy as np
31
+ import pandas as pd
32
+
33
+ # Örnek veri seti ve model eğitimi
34
+ data = pd.read_csv('data.csv')
35
+ X = data.drop('target', axis=1)
36
+ y = data['target']
37
+
38
+ model = RandomForestClassifier()
39
+ model.fit(X, y)
40
+
41
+ # Modeli kaydedin
42
+ with open('static/model/ai_model.pkl', 'wb') as file:
43
+ pickle.dump(model, file)
44
+
45
+
46
+ # In[3]:
47
+
48
+
49
+ from flask import Flask, render_template, request, jsonify
50
+ import pickle
51
+ import numpy as np
52
+ import pandas as pd
53
+
 
 
 
 
 
 
 
54
  app = Flask(__name__)
55
 
56
+ # Yapay zeka modelini yükleyin
57
+ with open('static/model/ai_model.pkl', 'rb') as file:
58
+ ai_model = pickle.load(file)
 
 
 
 
 
 
 
59
 
60
  @app.route('/')
61
+ def index():
62
  return render_template('index.html')
63
 
64
+ @app.route('/simulate', methods=['POST'])
65
+ def simulate():
66
+ user_input = request.json
67
+ # Yapay zeka modelini kullanarak tahmin yapın
68
+ features = np.array([user_input['data']]).reshape(1, -1)
69
+ prediction = ai_model.predict(features)[0]
70
+ return jsonify({'prediction': prediction})
71
+
72
+ @app.route('/result')
73
+ def result():
74
+ return render_template('result.html')
75
 
76
  if __name__ == '__main__':
77
+ app.run(debug=True)
78
+
79
+
80
+ # In[ ]:
81
+
82
+
83
+
84
+