File size: 1,317 Bytes
7197456
 
9c85732
 
 
622f8d4
aa239ce
622f8d4
 
 
aa239ce
 
 
 
 
 
 
 
 
 
 
367d07a
b2f4069
9c85732
367d07a
622f8d4
 
9c85732
8c2b61b
622f8d4
aa239ce
622f8d4
9c85732
7197456
 
 
b2f4069
9c85732
7197456
 
367d07a
9c85732
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
61
62
63
64
import spaces 
import gradio as gr 
import platform
import os;
import socket;
import torch
import torch.nn as nn

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

class SimpleModel(nn.Module):
    def __init__(self):
        super(SimpleModel, self).__init__()

    def forward(self, x):
        pass
        
    def device():
       return next(model.parameters()).device

model = SimpleModel().to(device);

@torch.inference_mode()
def sysinfo():
    RandomTensor = torch.randn(1, 2)  # Example audio tensor
    tensorExample = RandomTensor.to(device)
    
    return f"""

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

       device: {device}

       model device: {model.device}

       tensor: {tensorExample}

    """;

@spaces.GPU
def gpu():
     return sysinfo();


def nogpu():

    return sysinfo();



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"
    )