Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,15 +21,19 @@ def compute_similarity(input1, input2, type1, type2):
|
|
| 21 |
if type1 == "Image":
|
| 22 |
image1 = Image.open(input1).convert("RGB")
|
| 23 |
input1_tensor = processor(images=image1, return_tensors="pt")["pixel_values"]
|
| 24 |
-
|
| 25 |
input1_tensor = tokenizer(input1, return_tensors="pt")["input_ids"]
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Process input2
|
| 28 |
if type2 == "Image":
|
| 29 |
image2 = Image.open(input2).convert("RGB")
|
| 30 |
input2_tensor = processor(images=image2, return_tensors="pt")["pixel_values"]
|
| 31 |
-
|
| 32 |
input2_tensor = tokenizer(input2, return_tensors="pt")["input_ids"]
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Compute embeddings
|
| 35 |
with torch.no_grad():
|
|
|
|
| 21 |
if type1 == "Image":
|
| 22 |
image1 = Image.open(input1).convert("RGB")
|
| 23 |
input1_tensor = processor(images=image1, return_tensors="pt")["pixel_values"]
|
| 24 |
+
elif isinstance(input1, str) and input1.strip():
|
| 25 |
input1_tensor = tokenizer(input1, return_tensors="pt")["input_ids"]
|
| 26 |
+
else:
|
| 27 |
+
return "Error: Invalid text input for Input 1"
|
| 28 |
|
| 29 |
# Process input2
|
| 30 |
if type2 == "Image":
|
| 31 |
image2 = Image.open(input2).convert("RGB")
|
| 32 |
input2_tensor = processor(images=image2, return_tensors="pt")["pixel_values"]
|
| 33 |
+
elif isinstance(input2, str) and input2.strip():
|
| 34 |
input2_tensor = tokenizer(input2, return_tensors="pt")["input_ids"]
|
| 35 |
+
else:
|
| 36 |
+
return "Error: Invalid text input for Input 2"
|
| 37 |
|
| 38 |
# Compute embeddings
|
| 39 |
with torch.no_grad():
|