Spaces:
Running
Running
Download datacollection.py from Swapnilbpatil/Data_Collection: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/spaces/Swapnilbpatil/Data_Collection/resolve/main/datacollection.py
- Command line
-
hf download hf://spaces/Swapnilbpatil/Data_Collection/datacollection.py
-
curl -L -o datacollection.py https://huggingface.co/spaces/Swapnilbpatil/Data_Collection/resolve/main/datacollection.py
2.16 kB
| from flask import Flask, render_template, request, jsonify, send_file | |
| import csv | |
| import os | |
| from datetime import datetime | |
| app = Flask(__name__) | |
| CSV_FILE = 'data_collection.csv' | |
| # Create CSV file if it doesn't exist | |
| if not os.path.exists(CSV_FILE): | |
| with open(CSV_FILE, 'w', newline='') as f: | |
| writer = csv.writer(f) | |
| writer.writerow(['Human', 'AI', 'Timestamp']) | |
| def index(): | |
| return render_template('index.html') | |
| 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 | |
| # 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 | |
| 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 | |
| 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(debug=True) |