Update app.py
Browse files
app.py
CHANGED
|
@@ -165,10 +165,21 @@ def handle_input(user_prompt, image=None, audio=None, websearch=False, document=
|
|
| 165 |
print("1")
|
| 166 |
image = Image.open(image).convert('RGB')
|
| 167 |
print("2")
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
print("3")
|
| 170 |
-
|
| 171 |
print("4")
|
|
|
|
|
|
|
| 172 |
return response, None
|
| 173 |
else:
|
| 174 |
return "Please upload an image.", None
|
|
|
|
| 165 |
print("1")
|
| 166 |
image = Image.open(image).convert('RGB')
|
| 167 |
print("2")
|
| 168 |
+
|
| 169 |
+
# Add preprocessing steps here (see examples above)
|
| 170 |
+
preprocess = transforms.Compose([
|
| 171 |
+
transforms.Resize((512, 512)), # Example size, replace with the correct one
|
| 172 |
+
transforms.ToTensor(),
|
| 173 |
+
])
|
| 174 |
+
image = preprocess(image)
|
| 175 |
+
image = image.unsqueeze(0) # Add batch dimension
|
| 176 |
+
image = image.to(torch.float32) # Ensure correct data type
|
| 177 |
+
|
| 178 |
print("3")
|
| 179 |
+
messages = [{"role": "user", "content": user_prompt}]
|
| 180 |
print("4")
|
| 181 |
+
response = vqa_model.chat(image=image, msgs=messages, tokenizer=tokenizer, context=None, temperature=0.5)
|
| 182 |
+
print("5")
|
| 183 |
return response, None
|
| 184 |
else:
|
| 185 |
return "Please upload an image.", None
|