Ronith55 commited on
Commit
7fb9cbe
Β·
verified Β·
1 Parent(s): dd44da8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -2,26 +2,30 @@ import torch
2
  from transformers import AutoProcessor, AutoModelForVision2Seq
3
  from PIL import Image
4
 
5
- # βœ… Define the model name from Hugging Face
6
  MODEL_NAME = "deepseek-ai/deepseek-vl2-small"
7
 
8
- # βœ… Load model and processor
9
- processor = AutoProcessor.from_pretrained(MODEL_NAME)
10
- model = AutoModelForVision2Seq.from_pretrained(MODEL_NAME, torch_dtype=torch.float16)
 
 
 
 
11
 
12
- # βœ… Test the model with an image
13
  def predict(image_path):
14
  image = Image.open(image_path).convert("RGB")
15
-
16
  # Process input
17
  inputs = processor(images=image, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
18
 
19
  # Generate output
20
  output = model.generate(**inputs)
21
-
22
  # Decode response
23
  generated_text = processor.batch_decode(output, skip_special_tokens=True)[0]
24
-
25
  return generated_text
26
 
27
  # βœ… Example Usage
 
2
  from transformers import AutoProcessor, AutoModelForVision2Seq
3
  from PIL import Image
4
 
5
+ # βœ… Define the correct model name from Hugging Face
6
  MODEL_NAME = "deepseek-ai/deepseek-vl2-small"
7
 
8
+ # βœ… Load processor & model with `trust_remote_code=True`
9
+ processor = AutoProcessor.from_pretrained(MODEL_NAME, trust_remote_code=True)
10
+ model = AutoModelForVision2Seq.from_pretrained(
11
+ MODEL_NAME,
12
+ torch_dtype=torch.float16,
13
+ trust_remote_code=True # βœ… This allows loading custom model implementations
14
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
15
 
16
+ # βœ… Test function to process an image
17
  def predict(image_path):
18
  image = Image.open(image_path).convert("RGB")
19
+
20
  # Process input
21
  inputs = processor(images=image, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
22
 
23
  # Generate output
24
  output = model.generate(**inputs)
25
+
26
  # Decode response
27
  generated_text = processor.batch_decode(output, skip_special_tokens=True)[0]
28
+
29
  return generated_text
30
 
31
  # βœ… Example Usage