ACCA225 commited on
Commit
99b5e5c
1 Parent(s): 5262e8f

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +25 -11
app1.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  # import wandb
 
3
  os.chdir(f"/home/xlab-app-center")
4
  os.system(f"git clone https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-v1.6.1 /home/xlab-app-center/stable-diffusion-webui")
5
  os.system(f"cp /home/xlab-app-center/styles.csv /home/xlab-app-center/stable-diffusion-webui/styles.csv")
@@ -9,7 +10,7 @@ os.system(f"git reset --hard")
9
  os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/extensions")
10
 
11
  plugins = [
12
- "https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
13
  "https://gitcode.net/ranting8323/multidiffusion-upscaler-for-automatic1111",
14
  "https://gitcode.net/ranting8323/adetailer",
15
  "https://gitcode.net/ranting8323/sd-webui-prompt-all-in-one",
@@ -64,22 +65,35 @@ import os
64
  import threading
65
  import wandb
66
  import time
67
- def wandb():
68
- # Assuming you have initialized WandB before this function call
69
- # ...
70
 
 
 
 
 
71
  while True:
72
- # Loop to continuously monitor GPU temperature and usage
73
- gpu_temperature_command = "nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits"
74
- gpu_temperature = int(os.popen(gpu_temperature_command).read().strip())
75
- gpu_usage_command = "nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits"
76
- gpu_usage = int(os.popen(gpu_usage_command).read().strip())
 
 
 
 
 
 
 
 
 
77
 
78
- wandb.log({"GPU 温度": gpu_temperature, "GPU 使用率": gpu_usage})
79
  time.sleep(60)
80
 
 
81
  def start():
82
- os.system(f"python launch.py --api --xformers --enable-insecure-extension-access --ui-settings-file /home/xlab-app-center/config.json --ui-config-file /home/xlab-app-center/ui-config.json --gradio-queue --disable-safe-unpickle --ngrok=2Z4gIgLcc0W20vmdmTHTgwlWXdR_5aHNP91mnkn1mFYXUKKEz")
83
 
84
  # Create threads for each function
85
  wandb_thread = threading.Thread(target=wandb)
 
1
  import os
2
  # import wandb
3
+ os.system("pip install nvidia-ml-py3")
4
  os.chdir(f"/home/xlab-app-center")
5
  os.system(f"git clone https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-v1.6.1 /home/xlab-app-center/stable-diffusion-webui")
6
  os.system(f"cp /home/xlab-app-center/styles.csv /home/xlab-app-center/stable-diffusion-webui/styles.csv")
 
10
  os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/extensions")
11
 
12
  plugins = [
13
+ "https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-localization-zh_CN2",
14
  "https://gitcode.net/ranting8323/multidiffusion-upscaler-for-automatic1111",
15
  "https://gitcode.net/ranting8323/adetailer",
16
  "https://gitcode.net/ranting8323/sd-webui-prompt-all-in-one",
 
65
  import threading
66
  import wandb
67
  import time
68
+ import time
69
+ import nvidia_smi
70
+ import wandb
71
 
72
+ # 初始化 nvidia_smi
73
+ nvidia_smi.nvmlInit()
74
+
75
+ def wandb():
76
  while True:
77
+ try:
78
+ # 获取 GPU 温度
79
+ handle = nvidia_smi.nvmlDeviceGetHandleByIndex(0) # 0 表示第一个 GPU
80
+ gpu_temperature = nvidia_smi.nvmlDeviceGetTemperature(handle, nvidia_smi.NVML_TEMPERATURE_GPU)
81
+
82
+ # 获取 GPU 使用率
83
+ utilization = nvidia_smi.nvmlDeviceGetUtilizationRates(handle)
84
+ gpu_usage = utilization.gpu
85
+
86
+ # 使用 WandB 记录 GPU 温度和使用率
87
+ wandb.log({"GPU 温度": gpu_temperature, "GPU 使用率": gpu_usage})
88
+
89
+ except Exception as e:
90
+ print(f"Error: {e}")
91
 
 
92
  time.sleep(60)
93
 
94
+
95
  def start():
96
+ os.system(f"python launch.py --api --xformers --enable-insecure-extension-access --ui-settings-file /home/xlab-app-center/config.json --ui-config-file /home/xlab-app-center/ui-config.json --gradio-queue --disable-safe-unpickle")
97
 
98
  # Create threads for each function
99
  wandb_thread = threading.Thread(target=wandb)