Spaces:
Sleeping
Sleeping
fix app
Browse files
app.py
CHANGED
|
@@ -6,41 +6,37 @@ import socket
|
|
| 6 |
def fetch_url(url):
|
| 7 |
try:
|
| 8 |
r = requests.get(url, timeout=5)
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
except Exception as e:
|
| 14 |
-
return
|
| 15 |
|
| 16 |
def get_env():
|
| 17 |
-
|
| 18 |
for k, v in sorted(os.environ.items()):
|
| 19 |
-
|
| 20 |
-
return
|
| 21 |
|
| 22 |
def net_info():
|
| 23 |
hostname = socket.gethostname()
|
| 24 |
try:
|
| 25 |
ip = socket.gethostbyname(hostname)
|
| 26 |
-
except:
|
| 27 |
ip = "unknown"
|
|
|
|
| 28 |
try:
|
| 29 |
with open("/etc/resolv.conf") as f:
|
| 30 |
-
resolv
|
| 31 |
-
except:
|
| 32 |
-
|
| 33 |
try:
|
| 34 |
with open("/etc/hosts") as f:
|
| 35 |
-
hosts
|
| 36 |
-
except:
|
| 37 |
-
|
| 38 |
-
return
|
| 39 |
-
IP: {ip}
|
| 40 |
-
resolv.conf:
|
| 41 |
-
{resolv}
|
| 42 |
-
hosts:
|
| 43 |
-
{hosts}"
|
| 44 |
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
with gr.Tab("Fetch"):
|
|
|
|
| 6 |
def fetch_url(url):
|
| 7 |
try:
|
| 8 |
r = requests.get(url, timeout=5)
|
| 9 |
+
status = str(r.status_code)
|
| 10 |
+
headers = str(dict(r.headers))
|
| 11 |
+
body = r.text[:2000]
|
| 12 |
+
return "Status: " + status + "\nHeaders: " + headers + "\nBody:\n" + body
|
| 13 |
except Exception as e:
|
| 14 |
+
return "Error: " + str(e)
|
| 15 |
|
| 16 |
def get_env():
|
| 17 |
+
lines = []
|
| 18 |
for k, v in sorted(os.environ.items()):
|
| 19 |
+
lines.append(k + "=" + v[:100])
|
| 20 |
+
return "\n".join(lines)
|
| 21 |
|
| 22 |
def net_info():
|
| 23 |
hostname = socket.gethostname()
|
| 24 |
try:
|
| 25 |
ip = socket.gethostbyname(hostname)
|
| 26 |
+
except Exception:
|
| 27 |
ip = "unknown"
|
| 28 |
+
parts = ["Hostname: " + hostname, "IP: " + ip]
|
| 29 |
try:
|
| 30 |
with open("/etc/resolv.conf") as f:
|
| 31 |
+
parts.append("resolv.conf:\n" + f.read())
|
| 32 |
+
except Exception:
|
| 33 |
+
pass
|
| 34 |
try:
|
| 35 |
with open("/etc/hosts") as f:
|
| 36 |
+
parts.append("hosts:\n" + f.read())
|
| 37 |
+
except Exception:
|
| 38 |
+
pass
|
| 39 |
+
return "\n".join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
with gr.Tab("Fetch"):
|