Update app.py
Browse files
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
|
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 |
-
|
|
|
|
|
|
|
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(
|