Spaces:
Runtime error
Runtime error
cyborg-ai-git
commited on
Commit
•
0df55bd
1
Parent(s):
a554068
add gpu
Browse files- ai-comic-factory +1 -0
- app.py +51 -4
ai-comic-factory
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Subproject commit 11cdf4a219763f65eb38eb8f692a0f94eb973b43
|
app.py
CHANGED
@@ -1,7 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import datetime
|
3 |
+
import os
|
4 |
+
import subprocess
|
5 |
+
import torch
|
6 |
import gradio as gr
|
7 |
|
|
|
|
|
8 |
|
9 |
+
|
10 |
+
CUSTOM_CSS = """
|
11 |
+
#output_box textarea {
|
12 |
+
font-family: IBM Plex Mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
13 |
+
}
|
14 |
+
"""
|
15 |
+
|
16 |
+
zero = torch.Tensor([0]).cuda()
|
17 |
+
print(zero.device) # <-- 'cpu' 🤔
|
18 |
+
|
19 |
+
@spaces.GPU
|
20 |
+
def run_gpu() -> str:
|
21 |
+
print(zero.device) # <-- 'cuda:0'
|
22 |
+
output: str = ""
|
23 |
+
try:
|
24 |
+
output = subprocess.check_output(["nvidia-smi"], text=True)
|
25 |
+
except FileNotFoundError:
|
26 |
+
output = "nvidia-smi failed"
|
27 |
+
comment = (
|
28 |
+
datetime.datetime.now().replace(microsecond=0).isoformat().replace("T", " ")
|
29 |
+
)
|
30 |
+
return f"# {comment}\n\n{output}"
|
31 |
+
|
32 |
+
def run(check: bool) -> str:
|
33 |
+
if check:
|
34 |
+
return run_gpu()
|
35 |
+
else:
|
36 |
+
comment = (
|
37 |
+
datetime.datetime.now().replace(microsecond=0).isoformat().replace("T", " ")
|
38 |
+
)
|
39 |
+
return f"# {comment}"
|
40 |
+
|
41 |
+
output = gr.Textbox(
|
42 |
+
label="Command Output", max_lines=32, elem_id="output_box", value=run(False)
|
43 |
+
)
|
44 |
+
|
45 |
+
with gr.Blocks(css=CUSTOM_CSS) as demo:
|
46 |
+
#gr.Markdown("#### `zero-gpu`: how to run on serverless GPU for free on Spaces 🔥")
|
47 |
+
|
48 |
+
output.render()
|
49 |
+
|
50 |
+
check = gr.Checkbox(label="Run")
|
51 |
+
|
52 |
+
check.change(run, inputs=[check], outputs=output, every=1)
|
53 |
+
|
54 |
+
demo.queue().launch(show_api=True,share=True)
|