Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,11 @@ from PIL import Image
|
|
| 7 |
import requests
|
| 8 |
from io import BytesIO
|
| 9 |
import logging
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
import os
|
| 12 |
|
| 13 |
# Set cache directories
|
|
@@ -94,7 +98,7 @@ def get_image_embedding(image: Image.Image):
|
|
| 94 |
image_features = model.encode_image(image_tensor)
|
| 95 |
# Normalize the embedding
|
| 96 |
image_features = image_features / image_features.norm(dim=-1, keepdim=True)
|
| 97 |
-
return image_features.squeeze().cpu()
|
| 98 |
except Exception as e:
|
| 99 |
raise HTTPException(status_code=500, detail=f"Failed to process image: {str(e)}")
|
| 100 |
|
|
@@ -106,7 +110,7 @@ def get_text_embedding(text: str):
|
|
| 106 |
text_features = model.encode_text(text_tokens)
|
| 107 |
# Normalize the embedding
|
| 108 |
text_features = text_features / text_features.norm(dim=-1, keepdim=True)
|
| 109 |
-
return text_features.squeeze().cpu()
|
| 110 |
except Exception as e:
|
| 111 |
raise HTTPException(status_code=500, detail=f"Failed to process text: {str(e)}")
|
| 112 |
|
|
|
|
| 7 |
import requests
|
| 8 |
from io import BytesIO
|
| 9 |
import logging
|
| 10 |
+
try:
|
| 11 |
+
import numpy as np
|
| 12 |
+
print("✅ NumPy imported successfully:", np.__version__)
|
| 13 |
+
except ImportError as e:
|
| 14 |
+
print("❌ NumPy failed to import:", str(e))
|
| 15 |
import os
|
| 16 |
|
| 17 |
# Set cache directories
|
|
|
|
| 98 |
image_features = model.encode_image(image_tensor)
|
| 99 |
# Normalize the embedding
|
| 100 |
image_features = image_features / image_features.norm(dim=-1, keepdim=True)
|
| 101 |
+
return image_features.squeeze().cpu()
|
| 102 |
except Exception as e:
|
| 103 |
raise HTTPException(status_code=500, detail=f"Failed to process image: {str(e)}")
|
| 104 |
|
|
|
|
| 110 |
text_features = model.encode_text(text_tokens)
|
| 111 |
# Normalize the embedding
|
| 112 |
text_features = text_features / text_features.norm(dim=-1, keepdim=True)
|
| 113 |
+
return text_features.squeeze().cpu()
|
| 114 |
except Exception as e:
|
| 115 |
raise HTTPException(status_code=500, detail=f"Failed to process text: {str(e)}")
|
| 116 |
|