File size: 896 Bytes
0d78aa2 ff37d54 0d78aa2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
import subprocess
def get_ip(space_url):
try:
# Use the ping command to get the IP address
result = subprocess.run(["ping", "-c", "1", space_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
output = result.stdout
# Extract the IP address from the output
start = output.find("(") + 1
end = output.find(")")
ip_address = output[start:end]
if not ip_address:
return "Failed to retrieve IP address."
return ip_address
except Exception as e:
return str(e)
# Gradio interface
iface = gr.Interface(
fn=get_ip,
inputs="text",
outputs="text",
title="Get Hugging Face Space IP Address",
description="Enter the URL of your Hugging Face Space (e.g., your-space-url.hf.space) to retrieve its IP address."
)
iface.launch() |