gpu
Browse files
app.py
CHANGED
@@ -5,15 +5,13 @@ from deepseek_vl.models import VLChatProcessor, MultiModalityCausalLM
|
|
5 |
from deepseek_vl.utils.io import load_pil_images
|
6 |
from io import BytesIO
|
7 |
from PIL import Image
|
8 |
-
import spaces # Import spaces for ZeroGPU support
|
9 |
|
10 |
# Load the model and processor
|
11 |
model_path = "deepseek-ai/deepseek-vl-1.3b-chat"
|
12 |
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
13 |
tokenizer = vl_chat_processor.tokenizer
|
14 |
|
15 |
-
# Define the function for image description
|
16 |
-
@spaces.GPU # Ensures GPU allocation for this function
|
17 |
def describe_image(image, user_question="Solve the problem in the image"):
|
18 |
try:
|
19 |
# Convert the PIL Image to a BytesIO object for compatibility
|
@@ -43,10 +41,10 @@ def describe_image(image, user_question="Solve the problem in the image"):
|
|
43 |
conversations=conversation,
|
44 |
images=pil_images,
|
45 |
force_batchify=True
|
46 |
-
).to('
|
47 |
|
48 |
# Load and prepare the model
|
49 |
-
vl_gpt = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True).to(torch.bfloat16).
|
50 |
|
51 |
# Generate embeddings from the image input
|
52 |
inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
|
|
|
5 |
from deepseek_vl.utils.io import load_pil_images
|
6 |
from io import BytesIO
|
7 |
from PIL import Image
|
|
|
8 |
|
9 |
# Load the model and processor
|
10 |
model_path = "deepseek-ai/deepseek-vl-1.3b-chat"
|
11 |
vl_chat_processor = VLChatProcessor.from_pretrained(model_path)
|
12 |
tokenizer = vl_chat_processor.tokenizer
|
13 |
|
14 |
+
# Define the function for image description (CPU-only)
|
|
|
15 |
def describe_image(image, user_question="Solve the problem in the image"):
|
16 |
try:
|
17 |
# Convert the PIL Image to a BytesIO object for compatibility
|
|
|
41 |
conversations=conversation,
|
42 |
images=pil_images,
|
43 |
force_batchify=True
|
44 |
+
).to('cpu') # Move inputs to CPU
|
45 |
|
46 |
# Load and prepare the model
|
47 |
+
vl_gpt = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True).to(torch.bfloat16).cpu().eval() # Move model to CPU
|
48 |
|
49 |
# Generate embeddings from the image input
|
50 |
inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs)
|