adnaniqbal001 commited on
Commit
f66d625
·
verified ·
1 Parent(s): 3be3929

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -17
app.py CHANGED
@@ -12,32 +12,16 @@ c.execute('''CREATE TABLE IF NOT EXISTS counts
12
  (id INTEGER PRIMARY KEY, name TEXT, count INTEGER, timestamp TEXT)''')
13
  conn.commit()
14
 
15
- # Dummy counting function (replace with actual camera logic)
16
- def detect_material():
17
- # Yeh placeholder hai; actual OpenCV camera logic yahan aayega
18
- return 5 # Simulated count
19
-
20
  @app.route('/count', methods=['POST'])
21
  def count_material():
22
  data = request.json
23
  name = data.get('name', 'Unknown')
24
-
25
- # Counting logic (camera se replace karo)
26
- count = detect_material()
27
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
28
-
29
- # Save to database
30
  c.execute("INSERT INTO counts (name, count, timestamp) VALUES (?, ?, ?)",
31
  (name, count, timestamp))
32
  conn.commit()
33
-
34
  return jsonify({"material": name, "count": count, "timestamp": timestamp})
35
 
36
- @app.route('/view', methods=['GET'])
37
- def view_counts():
38
- c.execute("SELECT * FROM counts")
39
- results = c.fetchall()
40
- return jsonify([{"id": r[0], "name": r[1], "count": r[2], "timestamp": r[3]} for r in results])
41
-
42
  if __name__ == '__main__':
43
  app.run(host='0.0.0.0', port=7860)
 
12
  (id INTEGER PRIMARY KEY, name TEXT, count INTEGER, timestamp TEXT)''')
13
  conn.commit()
14
 
 
 
 
 
 
15
  @app.route('/count', methods=['POST'])
16
  def count_material():
17
  data = request.json
18
  name = data.get('name', 'Unknown')
19
+ count = 5 # Placeholder (camera logic baad mein add karo)
 
 
20
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
 
 
21
  c.execute("INSERT INTO counts (name, count, timestamp) VALUES (?, ?, ?)",
22
  (name, count, timestamp))
23
  conn.commit()
 
24
  return jsonify({"material": name, "count": count, "timestamp": timestamp})
25
 
 
 
 
 
 
 
26
  if __name__ == '__main__':
27
  app.run(host='0.0.0.0', port=7860)