ConstantCoder commited on
Commit
74b60dd
·
verified ·
1 Parent(s): e7e913c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -1,31 +1,23 @@
1
- from flask import Flask, request, jsonify
2
- from sklearn.tree import DecisionTreeClassifier
3
- import numpy as np
4
 
5
  app = Flask(__name__)
6
 
7
- # Basit örnek veriler (Bu veriler yerel olarak tutulabilir)
8
- # Örnek veri formatı: [phishing_response, ransomware_response, ddos_response, malware_response]
9
- example_data = [
10
- [0, 0, 1, 1],
11
- [1, 1, 0, 0],
12
- [1, 0, 1, 0],
13
- [0, 1, 0, 1]
14
- ]
15
 
16
- # Örnek sonuçlar: 1 = güvenli, 0 = güvensiz
17
- example_labels = [1, 0, 1, 0]
 
18
 
19
- # Model eğitimi
20
- model = DecisionTreeClassifier()
21
- model.fit(example_data, example_labels)
22
-
23
- @app.route('/analyze', methods=['POST'])
24
- def analyze():
25
- data = request.json
26
- response = [data['phishing'], data['ransomware'], data['ddos'], data['malware']]
27
- prediction = model.predict([response])
28
- return jsonify({'prediction': int(prediction[0])})
29
 
30
  if __name__ == '__main__':
31
- app.run(debug=True)
 
1
+ from flask import Flask, request, jsonify, send_from_directory
2
+ import os
 
3
 
4
  app = Flask(__name__)
5
 
6
+ @app.route('/')
7
+ def index():
8
+ return send_from_directory('.', 'index.html')
 
 
 
 
 
9
 
10
+ @app.route('/<path:path>')
11
+ def static_files(path):
12
+ return send_from_directory('.', path)
13
 
14
+ @app.route('/log', methods=['POST'])
15
+ def log_action():
16
+ action_log = request.get_json()
17
+ log_file_path = os.path.join(app.root_path, 'user_actions.json')
18
+ with open(log_file_path, 'a') as f:
19
+ f.write(f"{action_log}\n")
20
+ return jsonify({"status": "success"}), 200
 
 
 
21
 
22
  if __name__ == '__main__':
23
+ app.run(debug=True)