Swapnilbpatil commited on
Commit
7edf369
·
verified ·
1 Parent(s): e93b36f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify, send_file
2
+ import csv
3
+ import os
4
+ from datetime import datetime
5
+
6
+ app = Flask(__name__)
7
+ CSV_FILE = 'data_collection.csv'
8
+
9
+ # Create CSV file if it doesn't exist
10
+ if not os.path.exists(CSV_FILE):
11
+ with open(CSV_FILE, 'w', newline='') as f:
12
+ writer = csv.writer(f)
13
+ writer.writerow(['Human', 'AI', 'Timestamp'])
14
+
15
+ @app.route('/')
16
+ def index():
17
+ return render_template('index.html')
18
+
19
+ @app.route('/add_data', methods=['POST'])
20
+ def add_data():
21
+ try:
22
+ data = request.json
23
+ person1 = data.get('person1', '').strip()
24
+ person2 = data.get('person2', '').strip()
25
+
26
+ if not person1 or not person2:
27
+ return jsonify({'success': False, 'message': 'Both fields are required'}), 400
28
+
29
+ # Append to CSV
30
+ with open(CSV_FILE, 'a', newline='') as f:
31
+ writer = csv.writer(f)
32
+ timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
33
+ writer.writerow([person1, person2, timestamp])
34
+
35
+ return jsonify({'success': True, 'message': 'Data added successfully'})
36
+ except Exception as e:
37
+ return jsonify({'success': False, 'message': str(e)}), 500
38
+
39
+ @app.route('/verify_password', methods=['POST'])
40
+ def verify_password():
41
+ try:
42
+ data = request.json
43
+ password = data.get('password', '')
44
+
45
+ # Convert to int and compare
46
+ if int(password) == 8767575090:
47
+ return jsonify({'success': True})
48
+ else:
49
+ return jsonify({'success': False, 'message': 'Incorrect password'}), 401
50
+ except ValueError:
51
+ return jsonify({'success': False, 'message': 'Invalid password format'}), 400
52
+ except Exception as e:
53
+ return jsonify({'success': False, 'message': str(e)}), 500
54
+
55
+ @app.route('/download_csv')
56
+ def download_csv():
57
+ try:
58
+ return send_file(CSV_FILE, as_attachment=True, download_name='data_collection.csv')
59
+ except Exception as e:
60
+ return jsonify({'success': False, 'message': str(e)}), 500
61
+
62
+ if __name__ == '__main__':
63
+ app.run(host='0.0.0.0', port=7860, debug=False)