Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import requests
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def get_ip():
|
| 6 |
+
try:
|
| 7 |
+
ip = requests.get("https://ifconfig.me", timeout=10).text.strip()
|
| 8 |
+
except Exception as e:
|
| 9 |
+
ip = f"Error: {e}"
|
| 10 |
+
return ip
|
| 11 |
+
|
| 12 |
+
# Fetch at startup so it's immediately visible in logs
|
| 13 |
+
MY_IP = get_ip()
|
| 14 |
+
print(f"\n{'='*40}")
|
| 15 |
+
print(f" PUBLIC IP: {MY_IP}")
|
| 16 |
+
print(f"{'='*40}\n")
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
gr.Markdown("## IP Reporter")
|
| 20 |
+
ip_box = gr.Textbox(label="Public outbound IP of this Space", value=MY_IP)
|
| 21 |
+
refresh = gr.Button("Refresh")
|
| 22 |
+
refresh.click(fn=get_ip, outputs=ip_box)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|