OnlyCheeini's picture
Update app.py
0d78aa2 verified
raw
history blame
894 Bytes
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()