Spaces:
Sleeping
Sleeping
from flask import Flask, request, jsonify | |
import cv2 | |
import sqlite3 | |
from datetime import datetime | |
app = Flask(__name__) | |
# Database setup | |
conn = sqlite3.connect('materials.db', check_same_thread=False) | |
c = conn.cursor() | |
c.execute('''CREATE TABLE IF NOT EXISTS counts | |
(id INTEGER PRIMARY KEY, name TEXT, count INTEGER, timestamp TEXT)''') | |
conn.commit() | |
def count_material(): | |
data = request.json | |
name = data.get('name', 'Unknown') | |
count = 5 # Placeholder (camera logic baad mein add karo) | |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
c.execute("INSERT INTO counts (name, count, timestamp) VALUES (?, ?, ?)", | |
(name, count, timestamp)) | |
conn.commit() | |
return jsonify({"material": name, "count": count, "timestamp": timestamp}) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=7860) |