Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,9 +29,22 @@ from transformers.image_utils import load_image
|
|
| 29 |
# --- Constants and Model Setup ---
|
| 30 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
| 31 |
# Note: The following line correctly falls back to CPU if CUDA is not available.
|
| 32 |
-
#
|
| 33 |
-
#
|
| 34 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# --- Prompts for Different Tasks ---
|
| 37 |
layout_prompt = """Please output the layout information from the image, including each layout element's bbox, its category, and the corresponding text content within the bbox.
|
|
|
|
| 29 |
# --- Constants and Model Setup ---
|
| 30 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
| 31 |
# Note: The following line correctly falls back to CPU if CUDA is not available.
|
| 32 |
+
# Let the environment (e.g., Hugging Face Spaces) determine the device.
|
| 33 |
+
# This avoids conflicts with the CUDA environment setup by the platform.
|
| 34 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 35 |
+
|
| 36 |
+
print("CUDA_VISIBLE_DEVICES=", os.environ.get("CUDA_VISIBLE_DEVICES"))
|
| 37 |
+
print("torch.__version__ =", torch.__version__)
|
| 38 |
+
print("torch.version.cuda =", torch.version.cuda)
|
| 39 |
+
print("cuda available:", torch.cuda.is_available())
|
| 40 |
+
print("cuda device count:", torch.cuda.device_count())
|
| 41 |
+
if torch.cuda.is_available():
|
| 42 |
+
print("current device:", torch.cuda.current_device())
|
| 43 |
+
print("device name:", torch.cuda.get_device_name(torch.cuda.current_device()))
|
| 44 |
+
|
| 45 |
+
print("Using device:", device)
|
| 46 |
+
|
| 47 |
+
# --- Model Loading ---
|
| 48 |
|
| 49 |
# --- Prompts for Different Tasks ---
|
| 50 |
layout_prompt = """Please output the layout information from the image, including each layout element's bbox, its category, and the corresponding text content within the bbox.
|