wilwork commited on
Commit
2a4d3cb
·
verified ·
1 Parent(s): fe46f6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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 to text or PIL 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): # If it's a NumPy array (Gradio default)
16
- image = Image.fromarray(input_data)
17
- else:
18
- return None # Invalid input type
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