Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import torch
|
2 |
-
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
-
# β
|
6 |
pipe = pipeline("image-text-to-text", model="deepseek-ai/deepseek-vl2-small", trust_remote_code=True)
|
7 |
|
8 |
# β
Load model directly (alternative approach)
|
@@ -10,13 +11,20 @@ model = AutoModel.from_pretrained("deepseek-ai/deepseek-vl2-small", trust_remote
|
|
10 |
|
11 |
# β
Function to process image and text
|
12 |
def predict(image_path, text_prompt):
|
13 |
-
|
|
|
|
|
|
|
14 |
messages = [{"role": "user", "content": text_prompt}]
|
15 |
result = pipe(image, messages)
|
16 |
return result
|
17 |
|
18 |
# β
Example usage
|
19 |
if __name__ == "__main__":
|
20 |
-
|
|
|
21 |
prompt = "Describe this image."
|
22 |
-
|
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
import os
|
3 |
from PIL import Image
|
4 |
+
from transformers import pipeline, AutoModel
|
5 |
|
6 |
+
# β
Load the model using pipeline
|
7 |
pipe = pipeline("image-text-to-text", model="deepseek-ai/deepseek-vl2-small", trust_remote_code=True)
|
8 |
|
9 |
# β
Load model directly (alternative approach)
|
|
|
11 |
|
12 |
# β
Function to process image and text
|
13 |
def predict(image_path, text_prompt):
|
14 |
+
# Ensure correct path format for Windows/Linux
|
15 |
+
image_path = image_path.replace("\\", "/")
|
16 |
+
image = Image.open(image_path).convert("RGB")
|
17 |
+
|
18 |
messages = [{"role": "user", "content": text_prompt}]
|
19 |
result = pipe(image, messages)
|
20 |
return result
|
21 |
|
22 |
# β
Example usage
|
23 |
if __name__ == "__main__":
|
24 |
+
# Replace this with the correct image path
|
25 |
+
test_image = "sample_img2.JPG" # Ensure this image exists in the same folder
|
26 |
prompt = "Describe this image."
|
27 |
+
|
28 |
+
# Run prediction
|
29 |
+
output = predict(test_image, prompt)
|
30 |
+
print("Generated Response:", output)
|