Spaces:
Sleeping
Sleeping
Commit ·
148668c
1
Parent(s): efa9970
IP limit testing (set 1 per day)
Browse files
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
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 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 |
|