Update app.py
Browse files123456789101112131415161718192021222324252627282930313233import gradio as grimport subprocessdef get_ip(space_url):try:# Use the ping command to get the IP addressresult = subprocess.run(["ping", "-c", "1", space_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)output = result.stdout# Extract the IP address from the outputstart = output.find("(") + 1end = output.find(")")ip_address = output[start:end]if not ip_address:return "Failed to retrieve IP address."return ip_addressexcept Exception as e:return str(e)# Gradio interfaceiface = 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()1234567import gradio as grdef greet(name, req: gr.Request):return f"{req.headers=}"iface = gr.Interface(fn=greet, inputs="text", outputs="text")iface.launch()
app.py+3-29