edreesi commited on
Commit
9c1d3fc
·
verified ·
1 Parent(s): ca9b0c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -5,6 +5,11 @@ import gradio as gr
5
  import json
6
  import requests
7
  from PIL import Image
 
 
 
 
 
8
 
9
  css = """
10
  .example-image img{
@@ -44,6 +49,40 @@ css = """
44
  }
45
  """
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  screenReplayThreshold = 0.5
48
  portraitReplaceThreshold = 0.5
49
  printedCopyThreshold = 0.5
@@ -134,6 +173,14 @@ def check_liveness(frame):
134
  return [liveness_result, {"status": "error", "result": f"{result.text}"}]
135
 
136
  def idcard_recognition(frame1):
 
 
 
 
 
 
 
 
137
  url = "https://api.cortex.cerebrium.ai/v4/p-4f1d877e/my-first-project/process-image/"
138
  # url = "https://edreesi-ocr-api.hf.space/process-image/"
139
 
 
5
  import json
6
  import requests
7
  from PIL import Image
8
+ from flask import request
9
+ import sqlite3
10
+ from datetime import datetime, timedelta
11
+ # Initialize SQLite database
12
+
13
 
14
  css = """
15
  .example-image img{
 
49
  }
50
  """
51
 
52
+ # Initialize SQLite database
53
+ conn = sqlite3.connect("ip_requests.db")
54
+ cursor = conn.cursor()
55
+ cursor.execute("""
56
+ CREATE TABLE IF NOT EXISTS requests (
57
+ ip_address TEXT PRIMARY KEY,
58
+ count INTEGER,
59
+ last_request TIMESTAMP
60
+ )
61
+ """)
62
+ conn.commit()
63
+
64
+ def track_requests(ip_address):
65
+ now = datetime.now()
66
+ cursor.execute("SELECT count, last_request FROM requests WHERE ip_address=?", (ip_address,))
67
+ result = cursor.fetchone()
68
+
69
+ if result:
70
+ count, last_request = result
71
+ last_request = datetime.strptime(last_request, "%Y-%m-%d %H:%M:%S")
72
+ if now - last_request > timedelta(days=1):
73
+ count = 0
74
+ else:
75
+ count = 0
76
+
77
+ count += 1
78
+ cursor.execute("""
79
+ INSERT OR REPLACE INTO requests (ip_address, count, last_request)
80
+ VALUES (?, ?, ?)
81
+ """, (ip_address, count, now.strftime("%Y-%m-%d %H:%M:%S")))
82
+ conn.commit()
83
+ return count
84
+
85
+
86
  screenReplayThreshold = 0.5
87
  portraitReplaceThreshold = 0.5
88
  printedCopyThreshold = 0.5
 
173
  return [liveness_result, {"status": "error", "result": f"{result.text}"}]
174
 
175
  def idcard_recognition(frame1):
176
+ ip_address = request.remote_addr
177
+ request_count = track_requests(ip_address)
178
+
179
+ if request_count > 3:
180
+ print("you have exceeded the daily limit of 5 requests")
181
+ return "You have exceeded the daily limit of 5 requests."
182
+
183
+
184
  url = "https://api.cortex.cerebrium.ai/v4/p-4f1d877e/my-first-project/process-image/"
185
  # url = "https://edreesi-ocr-api.hf.space/process-image/"
186