Spaces:
Running
on
Zero
Running
on
Zero
test zerogpu space
Browse files- app.py +23 -2
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -1,9 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
| 3 |
|
| 4 |
@spaces.GPU
|
| 5 |
def greet(name):
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 9 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
@spaces.GPU
|
| 6 |
def greet(name):
|
| 7 |
+
# Détection du GPU
|
| 8 |
+
if torch.cuda.is_available():
|
| 9 |
+
device_name = torch.cuda.get_device_name(0)
|
| 10 |
+
device = torch.device("cuda")
|
| 11 |
+
else:
|
| 12 |
+
device_name = "CPU (aucun GPU détecté)"
|
| 13 |
+
device = torch.device("cpu")
|
| 14 |
+
|
| 15 |
+
# Crée un tenseur sur GPU ou CPU
|
| 16 |
+
tensor = torch.tensor([len(name)], dtype=torch.float32, device=device)
|
| 17 |
+
|
| 18 |
+
# Retourne une info lisible
|
| 19 |
+
result = f"Tensor: {tensor.cpu().numpy()} | Device: {device_name}"
|
| 20 |
+
return result
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=greet,
|
| 24 |
+
inputs="text",
|
| 25 |
+
outputs="text",
|
| 26 |
+
title="GPU Info Demo",
|
| 27 |
+
description="Retourne un tenseur et le nom du GPU utilisé"
|
| 28 |
+
)
|
| 29 |
|
|
|
|
| 30 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1 +1,3 @@
|
|
| 1 |
-
gradio
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
spaces
|
| 3 |
+
torch
|