prithivMLmods commited on
Commit
084ca31
·
verified ·
1 Parent(s): 89e803a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -3
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
- # The "RuntimeError: CUDA driver initialization failed" is an environment issue,
33
- # meaning the code is being run where a GPU is expected but not found/configured.
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.