Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,15 @@ import torch
|
|
7 |
# Load JinaAI CLIP model
|
8 |
model = AutoModel.from_pretrained("jinaai/jina-clip-v1", trust_remote_code=True)
|
9 |
|
10 |
-
# Function to process input (convert
|
11 |
def process_input(input_data, input_type):
|
12 |
if input_type == "Text":
|
13 |
return model.encode_text([input_data]) if input_data.strip() else None
|
14 |
elif input_type == "Image":
|
15 |
-
if isinstance(input_data, np.ndarray): #
|
16 |
-
image = Image.fromarray(input_data)
|
17 |
-
|
18 |
-
|
19 |
-
return model.encode_image([image])
|
20 |
return None
|
21 |
|
22 |
# Function to compute similarity
|
|
|
7 |
# Load JinaAI CLIP model
|
8 |
model = AutoModel.from_pretrained("jinaai/jina-clip-v1", trust_remote_code=True)
|
9 |
|
10 |
+
# Function to process input (convert text or image)
|
11 |
def process_input(input_data, input_type):
|
12 |
if input_type == "Text":
|
13 |
return model.encode_text([input_data]) if input_data.strip() else None
|
14 |
elif input_type == "Image":
|
15 |
+
if isinstance(input_data, np.ndarray): # Gradio provides image as NumPy array
|
16 |
+
image = Image.fromarray(input_data) # Convert NumPy array to PIL Image
|
17 |
+
return model.encode_image([image])
|
18 |
+
return None # Invalid input type
|
|
|
19 |
return None
|
20 |
|
21 |
# Function to compute similarity
|