Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,7 @@ import time
|
|
8 |
logging.basicConfig(level=logging.INFO)
|
9 |
|
10 |
css = """
|
11 |
-
footer {
|
12 |
-
visibility: hidden;
|
13 |
-
}
|
14 |
"""
|
15 |
|
16 |
# Function to check the status of a URL
|
@@ -19,21 +17,19 @@ def check_url_status():
|
|
19 |
response = requests.get("http://hugpu.ai:8000")
|
20 |
if response.status_code == 200:
|
21 |
logging.info("URL access successful: Status code 200")
|
22 |
-
return "Normal", "green"
|
23 |
else:
|
24 |
logging.error(f"URL access error: Status code {response.status_code}")
|
25 |
-
return "Abnormal", "red"
|
26 |
except requests.exceptions.RequestException as e:
|
27 |
logging.exception("Unable to connect to the server.")
|
28 |
-
return "Abnormal", "red"
|
29 |
|
30 |
# Function to update status
|
31 |
-
def update_status(
|
32 |
while True:
|
33 |
status, color = check_url_status()
|
34 |
-
|
35 |
-
status_box.update(style={'backgroundColor': color}) # Correct method to update style
|
36 |
-
logging.info(f"Status update: {status}")
|
37 |
time.sleep(6) # Wait for 6 seconds
|
38 |
|
39 |
# Gradio interface setup
|
@@ -45,15 +41,33 @@ def create_dashboard():
|
|
45 |
gr.Markdown("### Home description: [Link](https://seawolf2357-bnews1.hf.space)")
|
46 |
gr.Markdown("## \n")
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
status_box = gr.Label(value="", elem_id="status_box")
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
55 |
return app
|
56 |
|
57 |
if __name__ == "__main__":
|
58 |
dashboard = create_dashboard()
|
59 |
dashboard.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
logging.basicConfig(level=logging.INFO)
|
9 |
|
10 |
css = """
|
11 |
+
footer { visibility: hidden; }
|
|
|
|
|
12 |
"""
|
13 |
|
14 |
# Function to check the status of a URL
|
|
|
17 |
response = requests.get("http://hugpu.ai:8000")
|
18 |
if response.status_code == 200:
|
19 |
logging.info("URL access successful: Status code 200")
|
20 |
+
return "Normal", "green"
|
21 |
else:
|
22 |
logging.error(f"URL access error: Status code {response.status_code}")
|
23 |
+
return "Abnormal", "red"
|
24 |
except requests.exceptions.RequestException as e:
|
25 |
logging.exception("Unable to connect to the server.")
|
26 |
+
return "Abnormal", "red"
|
27 |
|
28 |
# Function to update status
|
29 |
+
def update_status():
|
30 |
while True:
|
31 |
status, color = check_url_status()
|
32 |
+
yield status, color
|
|
|
|
|
33 |
time.sleep(6) # Wait for 6 seconds
|
34 |
|
35 |
# Gradio interface setup
|
|
|
41 |
gr.Markdown("### Home description: [Link](https://seawolf2357-bnews1.hf.space)")
|
42 |
gr.Markdown("## \n")
|
43 |
|
44 |
+
status_label = gr.Textbox(label="AI Personal Assistant Status:", value="Loading...")
|
45 |
+
status_box = gr.Box(visible=False)
|
|
|
46 |
|
47 |
+
def update_ui(status, color):
|
48 |
+
return gr.Textbox.update(value=f"AI Personal Assistant Status: {status}"), gr.Box.update(visible=True, elem_id=f"status-{color.lower()}")
|
49 |
+
|
50 |
+
gr.Loop(update_status, outputs=[status_label, status_box], every=6, callback=update_ui)
|
51 |
+
|
52 |
return app
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
dashboard = create_dashboard()
|
56 |
dashboard.launch()
|
57 |
+
|
58 |
+
# Add this CSS to your Gradio interface or in a separate CSS file
|
59 |
+
custom_css = """
|
60 |
+
#status-green {
|
61 |
+
background-color: green;
|
62 |
+
color: white;
|
63 |
+
padding: 10px;
|
64 |
+
border-radius: 5px;
|
65 |
+
}
|
66 |
+
|
67 |
+
#status-red {
|
68 |
+
background-color: red;
|
69 |
+
color: white;
|
70 |
+
padding: 10px;
|
71 |
+
border-radius: 5px;
|
72 |
+
}
|
73 |
+
"""
|