ip-test-space-2 / app.py
Nottybro's picture
Upload app.py with huggingface_hub
0e4ff68 verified
Raw
History Blame Contribute Delete
584 Bytes
import requests
import gradio as gr
def get_ip():
try:
ip = requests.get("https://ifconfig.me", timeout=10).text.strip()
except Exception as e:
ip = f"Error: {e}"
return ip
# Fetch at startup so it's immediately visible in logs
MY_IP = get_ip()
print(f"\n{'='*40}")
print(f" PUBLIC IP: {MY_IP}")
print(f"{'='*40}\n")
with gr.Blocks() as demo:
gr.Markdown("## IP Reporter")
ip_box = gr.Textbox(label="Public outbound IP of this Space", value=MY_IP)
refresh = gr.Button("Refresh")
refresh.click(fn=get_ip, outputs=ip_box)
demo.launch()