Update app.py
Browse files
app.py
CHANGED
@@ -4,15 +4,12 @@ import socket
|
|
4 |
def predict(text, request: gr.Request):
|
5 |
client_ip = request.client.host
|
6 |
local_ip = socket.gethostbyname(socket.gethostbyname(""))
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
# x_forwarded_for = headers['x-forwarded-for']
|
14 |
-
# real_client_ip = x_forwarded_for.split(
|
15 |
-
# ' ')[0] if x_forwarded_for else ""
|
16 |
|
17 |
return text, {"real_client_ip": real_client_ip,
|
18 |
"client_ip": client_ip,
|
|
|
4 |
def predict(text, request: gr.Request):
|
5 |
client_ip = request.client.host
|
6 |
local_ip = socket.gethostbyname(socket.gethostbyname(""))
|
7 |
+
headers = request.kwargs['headers']
|
8 |
+
|
9 |
+
if headers and 'x-forwarded-for' in headers:
|
10 |
+
x_forwarded_for = headers['x-forwarded-for']
|
11 |
+
real_client_ip = x_forwarded_for.split(
|
12 |
+
' ')[0] if x_forwarded_for else ""
|
|
|
|
|
|
|
13 |
|
14 |
return text, {"real_client_ip": real_client_ip,
|
15 |
"client_ip": client_ip,
|