ktllc commited on
Commit
2b19e7c
·
1 Parent(s): fc5f1b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -27,7 +27,7 @@ def find_similarity(base64_image, text_input):
27
  text_tokens = clip.tokenize([text_input]).to(device)
28
 
29
  # Encode image and text features
30
- with torch.no_grad():
31
  image_features = model.encode_image(image)
32
  text_features = model.encode_text(text_tokens)
33
 
@@ -37,7 +37,10 @@ def find_similarity(base64_image, text_input):
37
  # Convert each element in the similarity array to Decimal
38
  similarity_decimal = [Decimal(float(score)) for score in similarity]
39
 
40
- return similarity_decimal
 
 
 
41
 
42
  # Create a Gradio interface
43
  iface = gr.Interface(
 
27
  text_tokens = clip.tokenize([text_input]).to(device)
28
 
29
  # Encode image and text features
30
+ with torch no grad():
31
  image_features = model.encode_image(image)
32
  text_features = model.encode_text(text_tokens)
33
 
 
37
  # Convert each element in the similarity array to Decimal
38
  similarity_decimal = [Decimal(float(score)) for score in similarity]
39
 
40
+ # Format Decimal values as floats with specific precision (e.g., 4 decimal places)
41
+ formatted_similarity = [f'{float(score):.5f}' for score in similarity_decimal]
42
+
43
+ return formatted_similarity
44
 
45
  # Create a Gradio interface
46
  iface = gr.Interface(