Frankie-walsh4 commited on
Commit
148668c
·
1 Parent(s): efa9970

IP limit testing (set 1 per day)

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -7,7 +7,6 @@ import traceback
7
  import datetime
8
  import threading
9
  from collections import defaultdict
10
- from flask import request
11
 
12
  """
13
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
@@ -43,11 +42,13 @@ THINKING_PATTERNS = [
43
  ]
44
 
45
  def get_client_ip():
46
- """Get the client's IP address from the request"""
47
  try:
48
- # Try to get IP from request context in a Flask environment
49
- if request:
50
- return request.remote_addr
 
 
51
  except:
52
  pass
53
 
 
7
  import datetime
8
  import threading
9
  from collections import defaultdict
 
10
 
11
  """
12
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
42
  ]
43
 
44
  def get_client_ip():
45
+ """Get the client's IP address from the request context"""
46
  try:
47
+ # Try to get IP from Gradio's request context
48
+ import contextvars
49
+ request_context = contextvars.ContextVar("request").get()
50
+ if hasattr(request_context, "client") and request_context.client:
51
+ return request_context.client.host
52
  except:
53
  pass
54