Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,12 @@ import torch
|
|
| 3 |
import subprocess
|
| 4 |
import os
|
| 5 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
def check_gpu():
|
| 8 |
results = []
|
| 9 |
|
|
@@ -50,6 +55,7 @@ def check_gpu():
|
|
| 50 |
|
| 51 |
return "\n".join(results)
|
| 52 |
|
|
|
|
| 53 |
def test_memory_allocation():
|
| 54 |
try:
|
| 55 |
# See how much GPU memory we can allocate
|
|
@@ -76,11 +82,30 @@ def test_memory_allocation():
|
|
| 76 |
except Exception as e:
|
| 77 |
return f"Memory test failed: {e}"
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
# Create the Gradio interface
|
| 80 |
with gr.Blocks(title="GPU Test") as demo:
|
| 81 |
gr.Markdown("# GPU Availability Test")
|
| 82 |
gr.Markdown("This app checks if GPU/CUDA is available and working in this Hugging Face Space")
|
| 83 |
|
|
|
|
|
|
|
|
|
|
| 84 |
with gr.Tab("Basic GPU Test"):
|
| 85 |
check_btn = gr.Button("Check GPU Status", variant="primary")
|
| 86 |
output = gr.Textbox(label="Results", lines=20)
|
|
|
|
| 3 |
import subprocess
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
+
from huggingface_hub import SpaceStage
|
| 7 |
+
from huggingface_hub.utils import RepositoryNotFoundError
|
| 8 |
+
from huggingface_hub.spaces import get_space_stage
|
| 9 |
+
import spaces
|
| 10 |
|
| 11 |
+
@spaces.GPU
|
| 12 |
def check_gpu():
|
| 13 |
results = []
|
| 14 |
|
|
|
|
| 55 |
|
| 56 |
return "\n".join(results)
|
| 57 |
|
| 58 |
+
@spaces.GPU
|
| 59 |
def test_memory_allocation():
|
| 60 |
try:
|
| 61 |
# See how much GPU memory we can allocate
|
|
|
|
| 82 |
except Exception as e:
|
| 83 |
return f"Memory test failed: {e}"
|
| 84 |
|
| 85 |
+
def get_space_status():
|
| 86 |
+
try:
|
| 87 |
+
stage = get_space_stage()
|
| 88 |
+
if stage == SpaceStage.RUNNING:
|
| 89 |
+
status = "Space is running"
|
| 90 |
+
elif stage == SpaceStage.BUILDING:
|
| 91 |
+
status = "Space is building"
|
| 92 |
+
else:
|
| 93 |
+
status = f"Space is in stage: {stage}"
|
| 94 |
+
except RepositoryNotFoundError:
|
| 95 |
+
status = "Not running in a Space"
|
| 96 |
+
except Exception as e:
|
| 97 |
+
status = f"Error getting Space stage: {e}"
|
| 98 |
+
|
| 99 |
+
return status
|
| 100 |
+
|
| 101 |
# Create the Gradio interface
|
| 102 |
with gr.Blocks(title="GPU Test") as demo:
|
| 103 |
gr.Markdown("# GPU Availability Test")
|
| 104 |
gr.Markdown("This app checks if GPU/CUDA is available and working in this Hugging Face Space")
|
| 105 |
|
| 106 |
+
# Display Space status
|
| 107 |
+
status_text = gr.Markdown(f"**Space Status**: {get_space_status()}")
|
| 108 |
+
|
| 109 |
with gr.Tab("Basic GPU Test"):
|
| 110 |
check_btn = gr.Button("Check GPU Status", variant="primary")
|
| 111 |
output = gr.Textbox(label="Results", lines=20)
|