Spaces:
Sleeping
Sleeping
debugging for ip ratelimting 3
Browse files
app.py
CHANGED
|
@@ -38,7 +38,14 @@ def chat_with_agent(question: str, file_uploads, history: list) -> tuple:
|
|
| 38 |
try:
|
| 39 |
# Get client IP for rate limiting using Gradio's request context
|
| 40 |
request = gr.Request()
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
print(f"Request from IP: {ip_address}")
|
| 43 |
|
| 44 |
# Check rate limit
|
|
|
|
| 38 |
try:
|
| 39 |
# Get client IP for rate limiting using Gradio's request context
|
| 40 |
request = gr.Request()
|
| 41 |
+
# Try to get IP from X-Forwarded-For header first, then fallback to client.host
|
| 42 |
+
ip_address = None
|
| 43 |
+
if request and hasattr(request, 'headers'):
|
| 44 |
+
ip_address = request.headers.get('X-Forwarded-For', '').split(',')[0].strip()
|
| 45 |
+
if not ip_address and request and hasattr(request, 'client'):
|
| 46 |
+
ip_address = request.client.host
|
| 47 |
+
if not ip_address:
|
| 48 |
+
ip_address = "127.0.0.1"
|
| 49 |
print(f"Request from IP: {ip_address}")
|
| 50 |
|
| 51 |
# Check rate limit
|