vykanand commited on
Commit
2319467
Β·
verified Β·
1 Parent(s): 409693f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import torch
 
 
2
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
3
  from qwen_vl_utils import process_vision_info
4
 
@@ -14,14 +16,23 @@ model = model.to(device)
14
  # Default processor
15
  processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
16
 
17
- # Prepare input messages
 
 
 
 
 
 
 
 
 
18
  messages = [
19
  {
20
  "role": "user",
21
  "content": [
22
  {
23
  "type": "image",
24
- "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
25
  },
26
  {"type": "text", "text": "Describe this image."},
27
  ],
@@ -56,4 +67,4 @@ output_text = processor.batch_decode(
56
  )
57
 
58
  # Print the output
59
- print(output_text)
 
1
  import torch
2
+ from PIL import Image
3
+ import requests
4
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
5
  from qwen_vl_utils import process_vision_info
6
 
 
16
  # Default processor
17
  processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
18
 
19
+ # Resize the image to a smaller resolution (e.g., 512x512)
20
+ image_url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
21
+ response = requests.get(image_url)
22
+ img = Image.open(BytesIO(response.content))
23
+
24
+ # Resize the image
25
+ img_resized = img.resize((512, 512)) # Resize the image to 512x512
26
+ image_inputs = processor(images=img_resized, return_tensors="pt").to(device)
27
+
28
+ # Prepare the text input
29
  messages = [
30
  {
31
  "role": "user",
32
  "content": [
33
  {
34
  "type": "image",
35
+ "image": img_resized,
36
  },
37
  {"type": "text", "text": "Describe this image."},
38
  ],
 
67
  )
68
 
69
  # Print the output
70
+ print(output_text)