eduardo-alvarez commited on
Commit
8342f96
·
verified ·
1 Parent(s): 5e1823c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -227,6 +227,34 @@ with demo:
227
  citation =gr.Textbox(value = CITATION_TEXT,
228
  lines=6,
229
  label="Use the following to cite this content")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
  gr.Markdown("""<div style="display: flex; justify-content: center;"> <p> Intel, the Intel logo and Gaudi are trademarks of Intel Corporation or its subsidiaries.
232
  *Other names and brands may be claimed as the property of others.
 
227
  citation =gr.Textbox(value = CITATION_TEXT,
228
  lines=6,
229
  label="Use the following to cite this content")
230
+
231
+ import gradio as gr
232
+ import socket
233
+
234
+ def predict(text, request: gr.Request):
235
+ client_ip = request.client.host
236
+ local_ip = socket.gethostbyname(socket.gethostbyname(""))
237
+ x_forwarded_for = request.headers.get('x-forwarded-for')
238
+ headers = request.headers
239
+ if x_forwarded_for:
240
+ client_ip = x_forwarded_for
241
+ print("client_ip", client_ip, text)
242
+ print("x_forwarded_for", x_forwarded_for)
243
+ return text, {"client_ip": client_ip,
244
+ "local_ip": local_ip,
245
+ "headers": headers}
246
+
247
+
248
+ with gr.Blocks() as block:
249
+ gr.Markdown("## Gradio get client IP")
250
+ text = gr.Textbox(label="dummy input")
251
+ output = gr.JSON({})
252
+ btn = gr.Button("Test")
253
+
254
+ btn.click(predict, inputs=[text], outputs=[text, output])
255
+
256
+ block.queue()
257
+ block.launch(share=False, server_name='0.0.0.0', show_api=True)
258
 
259
  gr.Markdown("""<div style="display: flex; justify-content: center;"> <p> Intel, the Intel logo and Gaudi are trademarks of Intel Corporation or its subsidiaries.
260
  *Other names and brands may be claimed as the property of others.