ruslanmv commited on
Commit
9ef77c2
·
1 Parent(s): abfefcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -8,6 +8,7 @@ import torch
8
  from transformers import AutoProcessor, MllamaForConditionalGeneration, TextStreamer
9
  from PIL import Image
10
  import csv
 
11
  # Check if we're running in a Hugging Face Space and if SPACES_ZERO_GPU is enabled
12
  IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
13
  IS_SPACE = os.environ.get("SPACE_ID", None) is not None
@@ -34,15 +35,21 @@ if IS_GDRVIE:
34
  )
35
  processor = AutoProcessor.from_pretrained(model_path)
36
  else:
37
- model_name = "ruslanmv/" + model_name
 
 
 
 
38
  model = MllamaForConditionalGeneration.from_pretrained(
39
  model_name,
40
  use_auth_token=HF_TOKEN,
41
- torch_dtype=torch.bfloat16,
42
- device_map="auto",
43
  )
44
- processor = AutoProcessor.from_pretrained(model_name, use_auth_token=HF_TOKEN)
45
 
 
 
 
46
 
47
 
48
  # Tie the model weights to ensure the model is properly loaded
 
8
  from transformers import AutoProcessor, MllamaForConditionalGeneration, TextStreamer
9
  from PIL import Image
10
  import csv
11
+ import spaces
12
  # Check if we're running in a Hugging Face Space and if SPACES_ZERO_GPU is enabled
13
  IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
14
  IS_SPACE = os.environ.get("SPACE_ID", None) is not None
 
35
  )
36
  processor = AutoProcessor.from_pretrained(model_path)
37
  else:
38
+ # Get Hugging Face token from environment variables
39
+ HF_TOKEN = os.environ.get('HF_TOKEN')
40
+
41
+ # Load the model and processor
42
+ model_name = "ruslanmv/Llama-3.2-11B-Vision-Instruct"
43
  model = MllamaForConditionalGeneration.from_pretrained(
44
  model_name,
45
  use_auth_token=HF_TOKEN,
46
+ torch_dtype=torch.bfloat16 if device == "cuda" else torch.float32,
47
+ device_map="auto" if device == "cuda" else None, # Use device mapping if CUDA is available
48
  )
 
49
 
50
+ # Move the model to the appropriate device (GPU if available)
51
+ model.to(device)
52
+ processor = AutoProcessor.from_pretrained(model_name, use_auth_token=HF_TOKEN)
53
 
54
 
55
  # Tie the model weights to ensure the model is properly loaded