Srinivasulu kethanaboina commited on
Commit
07313a7
·
verified ·
1 Parent(s): bb9219e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -14
app.py CHANGED
@@ -1,20 +1,52 @@
 
 
 
1
  import gradio as gr
2
- import requests
3
 
4
- def get_public_ip_address():
5
- try:
6
- response = requests.get('(link unavailable)')
7
- response.raise_for_status() # Raise an exception for bad status codes
8
- ip_address = response.json().get('ip', 'Unknown IP Address')
9
- except requests.RequestException as e:
10
- ip_address = f'Unable to retrieve IP address: {e}'
11
- return f"Your Public IP Address is: {ip_address}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  iface = gr.Interface(
14
- fn=get_public_ip_address,
15
- inputs=[],
16
- outputs="text",
17
- title="Public IP Address Display",
18
  description="This app shows your public IP address."
19
  )
20
- iface.launch()
 
 
 
1
+
2
+
3
+
4
  import gradio as gr
 
5
 
6
+ def get_html_with_ip():
7
+ html_code = """
8
+ <!DOCTYPE html>
9
+ <html lang="en">
10
+ <head>
11
+ <meta charset="UTF-8">
12
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
13
+ <title>Public IP Address</title>
14
+ <style>
15
+ body {
16
+ font-family: Arial, sans-serif;
17
+ text-align: center;
18
+ }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <h1>Your Public IP Address</h1>
23
+ <p id="ip-address">Loading...</p>
24
+ <script>
25
+ async function fetchPublicIP() {
26
+ try {
27
+ const response = await fetch('(link unavailable)');
28
+ const data = await response.json();
29
+ document.getElementById('ip-address').textContent = data.ip;
30
+ } catch (error) {
31
+ document.getElementById('ip-address').textContent = 'Unable to retrieve IP address';
32
+ console.error(error);
33
+ }
34
+ }
35
+ fetchPublicIP();
36
+ </script>
37
+ </body>
38
+ </html>
39
+ """
40
+ return html_code
41
+
42
 
43
  iface = gr.Interface(
44
+ fn=get_html_with_ip,
45
+ inputs=[],
46
+ outputs=gr.outputs.HTML(),
47
+ title="Public IP Address Display",
48
  description="This app shows your public IP address."
49
  )
50
+
51
+
52
+ iface.launch()