|
import gradio as gr |
|
import subprocess |
|
|
|
def get_ip(space_url): |
|
try: |
|
|
|
result = subprocess.run(["ping", "-c", "1", space_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
|
output = result.stdout |
|
|
|
|
|
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) |
|
|
|
|
|
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() |