new uptime
Browse files
app.py
CHANGED
|
@@ -7,6 +7,35 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
@tool
|
| 11 |
+
def get_the_current_uptime(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 12 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 13 |
+
"""This tools get the current system uptime
|
| 14 |
+
"""
|
| 15 |
+
import platform
|
| 16 |
+
import time
|
| 17 |
+
import os
|
| 18 |
+
system = platform.system()
|
| 19 |
+
try:
|
| 20 |
+
if system == "Linux":
|
| 21 |
+
with open("/proc/uptime", "r") as f:
|
| 22 |
+
uptime = float(f.readline().split()[0])
|
| 23 |
+
elif system == "Windows":
|
| 24 |
+
import ctypes
|
| 25 |
+
uptime = ctypes.windll.kernel32.GetTickCount64() / 1000.0
|
| 26 |
+
elif system == "Darwin":
|
| 27 |
+
boot_time = int(os.popen("sysctl -n kern.boottime").read().split("=")[1].strip().split()[0])
|
| 28 |
+
uptime = time.time() - boot_time
|
| 29 |
+
else:
|
| 30 |
+
return f"N/A ({system})"
|
| 31 |
+
days = int(uptime // 86400)
|
| 32 |
+
hours = int((uptime % 86400) // 3600)
|
| 33 |
+
minutes = int((uptime % 3600) // 60)
|
| 34 |
+
return f"{days}d {hours}h {minutes}m"
|
| 35 |
+
except Exception:
|
| 36 |
+
return "N/A"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 40 |
@tool
|
| 41 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|