Commit
·
c1ca8a4
1
Parent(s):
512d921
add app with reqs
Browse files- app.py +30 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Tuple
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def is_active(url) -> Tuple[bool, str]:
|
| 7 |
+
try:
|
| 8 |
+
response = requests.get(url, timeout=10)
|
| 9 |
+
if 200 <= response.status_code < 300:
|
| 10 |
+
return True, f"The website {url} is active."
|
| 11 |
+
else:
|
| 12 |
+
return False, f"The website {url} returned status code {response.status_code}."
|
| 13 |
+
except requests.ConnectionError:
|
| 14 |
+
return False, f"Failed to connect to {url}."
|
| 15 |
+
except requests.Timeout:
|
| 16 |
+
return False, f"The request to {url} timed out."
|
| 17 |
+
except requests.RequestException as e:
|
| 18 |
+
return False, f"An error occurred: {e}"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=is_active,
|
| 23 |
+
inputs="text",
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Website Activity Checker",
|
| 26 |
+
description="Enter a URL to check if the website is active.",
|
| 27 |
+
allow_flagging="never",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
requests
|