Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -39,7 +39,15 @@ app.add_middleware(
|
|
| 39 |
allow_headers=["*"],
|
| 40 |
)
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
feature_extractor = FeatureExtractor(base_model="vit_b_16")
|
| 44 |
|
| 45 |
if torch.backends.mps.is_built():
|
|
@@ -124,20 +132,18 @@ async def search_image(body: ImageSearchBody):
|
|
| 124 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 125 |
|
| 126 |
|
| 127 |
-
from src.firebase.firebase_provider import
|
| 128 |
-
upload_base64_image_to_storage,
|
| 129 |
-
)
|
| 130 |
|
| 131 |
|
| 132 |
class Body(BaseModel):
|
| 133 |
-
base64_image: str = Field(..., title="Base64 Image String")
|
| 134 |
-
image_name: str = Field(..., title="Image Name")
|
| 135 |
model_config = {
|
| 136 |
"json_schema_extra": {
|
| 137 |
"examples": [
|
| 138 |
{
|
| 139 |
-
"base64_image":
|
| 140 |
-
|
|
|
|
| 141 |
}
|
| 142 |
]
|
| 143 |
}
|
|
@@ -145,9 +151,9 @@ class Body(BaseModel):
|
|
| 145 |
|
| 146 |
|
| 147 |
@app.post("/upload_image")
|
| 148 |
-
def upload_image(body: Body):
|
| 149 |
try:
|
| 150 |
-
public_url =
|
| 151 |
return JSONResponse(content={"public_url": public_url}, status_code=200)
|
| 152 |
except Exception as e:
|
| 153 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
|
|
|
| 39 |
allow_headers=["*"],
|
| 40 |
)
|
| 41 |
|
| 42 |
+
index_path = "./model/db_vit_b_16.index"
|
| 43 |
+
|
| 44 |
+
if not os.path.exists(index_path):
|
| 45 |
+
raise FileNotFoundError(f"Index file not found: {index_path}")
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
index = faiss.read_index(index_path)
|
| 49 |
+
except RuntimeError as e:
|
| 50 |
+
raise RuntimeError(f"Error reading FAISS index: {e}")
|
| 51 |
feature_extractor = FeatureExtractor(base_model="vit_b_16")
|
| 52 |
|
| 53 |
if torch.backends.mps.is_built():
|
|
|
|
| 132 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
| 133 |
|
| 134 |
|
| 135 |
+
from src.firebase.firebase_provider import process_images
|
|
|
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
class Body(BaseModel):
|
| 139 |
+
base64_image: list[str] = Field(..., title="Base64 Image String")
|
|
|
|
| 140 |
model_config = {
|
| 141 |
"json_schema_extra": {
|
| 142 |
"examples": [
|
| 143 |
{
|
| 144 |
+
"base64_image": [
|
| 145 |
+
"iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABdUlEQVR42mNk",
|
| 146 |
+
]
|
| 147 |
}
|
| 148 |
]
|
| 149 |
}
|
|
|
|
| 151 |
|
| 152 |
|
| 153 |
@app.post("/upload_image")
|
| 154 |
+
async def upload_image(body: Body):
|
| 155 |
try:
|
| 156 |
+
public_url = await process_images(body.base64_image)
|
| 157 |
return JSONResponse(content={"public_url": public_url}, status_code=200)
|
| 158 |
except Exception as e:
|
| 159 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|