File size: 1,232 Bytes
7197456
 
9c85732
 
 
622f8d4
 
3dbc4a6
622f8d4
3dbc4a6
 
aa239ce
3dbc4a6
aa239ce
9b6e7fb
 
 
61f930c
 
622f8d4
f199171
 
9c85732
8c2b61b
622f8d4
 
f199171
9c85732
7197456
 
 
9c85732
61f930c
7197456
367d07a
61f930c
 
 
7197456
 
 
b194cd1
7197456
 
3f8ee6d
 
7b99542
34619cb
7b99542
 
7197456
 
 
 
 
 
 
10ecedc
7197456
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import spaces 
import gradio as gr 
import platform
import os;
import socket;
import torch

device = "cuda";

if not torch.cuda.is_available() and device == "cuda":
    raise RuntimeError("CUDA device unavailable, please use Dockerfile.cpu instead.") 

print("DEVICE: ", device);

RandomTensor = torch.randn(1, 2)  # Example audio tensor
RandomTensor.to(device)

def sysinfo(device):
    tensorExample = RandomTensor.to(device)
    
    tocpu = tensorExample.cpu().squeeze().half().tolist()
    
    return f"""

       hostname: {platform.node()} {socket.gethostname()}

       device: {device}

       tensor: {tensorExample}

       toCpu: {tocpu}

    """;

@spaces.GPU
def gpu():

     return sysinfo("cuda:0");


def nogpu():
    
    return sysinfo("cpu");



with gr.Blocks() as demo:
    outgpu = gr.Textbox(lines=5);
    outnpu = gr.Textbox(lines=5);
    btngpu = gr.Button(value="gpu");
    btngpun = gr.Button(value="ngpu");
    
    btngpu.click(gpu, None, [outgpu]);
    btngpun.click(nogpu, None, [outnpu]);
    


if __name__ == "__main__":
    demo.launch(
        share=False,
        debug=False,
        server_port=7860,
        server_name="0.0.0.0"
    )