radames commited on
Commit
b43d291
1 Parent(s): ae0e338

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
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
- headers = request.headers
9
- real_client_ip = ""
10
- print(headers)
11
- # print(dict(headers))
12
- # if headers and 'x-forwarded-for' in headers:
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,