File size: 2,470 Bytes
7edf369
 
 
 
 
 
84ec924
7edf369
 
84ec924
 
 
 
 
 
 
7edf369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ec924
 
 
 
 
 
7edf369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify, send_file
import csv
import os
from datetime import datetime

app = Flask(__name__)
CSV_FILE = '/tmp/data_collection.csv'

# Create CSV file if it doesn't exist
try:
    if not os.path.exists(CSV_FILE):
        with open(CSV_FILE, 'w', newline='') as f:
            writer = csv.writer(f)
            writer.writerow(['Human', 'AI', 'Timestamp'])
except Exception as e:
    print(f"Warning: Could not create CSV file: {e}")

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/add_data', methods=['POST'])
def add_data():
    try:
        data = request.json
        person1 = data.get('person1', '').strip()
        person2 = data.get('person2', '').strip()
        
        if not person1 or not person2:
            return jsonify({'success': False, 'message': 'Both fields are required'}), 400
        
        # Ensure CSV file exists
        if not os.path.exists(CSV_FILE):
            with open(CSV_FILE, 'w', newline='') as f:
                writer = csv.writer(f)
                writer.writerow(['Human', 'AI', 'Timestamp'])
        
        # Append to CSV
        with open(CSV_FILE, 'a', newline='') as f:
            writer = csv.writer(f)
            timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
            writer.writerow([person1, person2, timestamp])
        
        return jsonify({'success': True, 'message': 'Data added successfully'})
    except Exception as e:
        return jsonify({'success': False, 'message': str(e)}), 500

@app.route('/verify_password', methods=['POST'])
def verify_password():
    try:
        data = request.json
        password = data.get('password', '')
        
        # Convert to int and compare
        if int(password) == 8767575090:
            return jsonify({'success': True})
        else:
            return jsonify({'success': False, 'message': 'Incorrect password'}), 401
    except ValueError:
        return jsonify({'success': False, 'message': 'Invalid password format'}), 400
    except Exception as e:
        return jsonify({'success': False, 'message': str(e)}), 500

@app.route('/download_csv')
def download_csv():
    try:
        return send_file(CSV_FILE, as_attachment=True, download_name='data_collection.csv')
    except Exception as e:
        return jsonify({'success': False, 'message': str(e)}), 500

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860, debug=False)