Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,15 @@ except Exception as e:
|
|
| 21 |
|
| 22 |
# Function to generate embeddings from an image
|
| 23 |
def generate_embedding(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if image is None:
|
| 25 |
return {"error": "No image provided"}, "No image provided"
|
| 26 |
|
|
@@ -86,6 +95,15 @@ def generate_embedding(image):
|
|
| 86 |
|
| 87 |
# Function to generate embeddings from an image URL
|
| 88 |
def embed_image_from_url(image_url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
try:
|
| 90 |
# Download the image
|
| 91 |
response = requests.get(image_url)
|
|
|
|
| 21 |
|
| 22 |
# Function to generate embeddings from an image
|
| 23 |
def generate_embedding(image):
|
| 24 |
+
"""
|
| 25 |
+
Generate normalized embedding vector for the uploaded image.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
image (PIL.Image.Image or np.ndarray): Input image uploaded by the user.
|
| 29 |
+
|
| 30 |
+
Returns:
|
| 31 |
+
list[float]: A normalized image embedding vector representing the input image.
|
| 32 |
+
"""
|
| 33 |
if image is None:
|
| 34 |
return {"error": "No image provided"}, "No image provided"
|
| 35 |
|
|
|
|
| 95 |
|
| 96 |
# Function to generate embeddings from an image URL
|
| 97 |
def embed_image_from_url(image_url):
|
| 98 |
+
"""
|
| 99 |
+
Generate normalized embedding vector for the image from a URL.
|
| 100 |
+
|
| 101 |
+
Args:
|
| 102 |
+
image_url (str): Image URL provided by the User.
|
| 103 |
+
|
| 104 |
+
Returns:
|
| 105 |
+
list[float]: A normalized image embedding vector representing the input image.
|
| 106 |
+
"""
|
| 107 |
try:
|
| 108 |
# Download the image
|
| 109 |
response = requests.get(image_url)
|