Added fastapi functions for getting all cards in metadata
Browse files- app/main.py +8 -0
- app/services/similarity_service.py +10 -1
app/main.py
CHANGED
|
@@ -73,6 +73,14 @@ async def predict(payload: ImagePayload):
|
|
| 73 |
)
|
| 74 |
except Exception as e:
|
| 75 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
import uvicorn
|
| 78 |
|
|
|
|
| 73 |
)
|
| 74 |
except Exception as e:
|
| 75 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 76 |
+
|
| 77 |
+
@app.get("/cards")
|
| 78 |
+
def get_cards(limit: int = 50):
|
| 79 |
+
try:
|
| 80 |
+
cards = app.state.similarity_service.get_all_cards(limit=limit)
|
| 81 |
+
return cards
|
| 82 |
+
except Exception as e:
|
| 83 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 84 |
|
| 85 |
import uvicorn
|
| 86 |
|
app/services/similarity_service.py
CHANGED
|
@@ -45,4 +45,13 @@ class SimilarityService:
|
|
| 45 |
"score": float(score)
|
| 46 |
})
|
| 47 |
|
| 48 |
-
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
"score": float(score)
|
| 46 |
})
|
| 47 |
|
| 48 |
+
return results
|
| 49 |
+
|
| 50 |
+
def get_all_cards(self, limit: int = 50) -> list[dict]:
|
| 51 |
+
# Check if metadat is a dictionary
|
| 52 |
+
if isinstance(self.metadata, dict):
|
| 53 |
+
# Return metadata values
|
| 54 |
+
return list(self.metadata.values())[:limit]
|
| 55 |
+
|
| 56 |
+
# Return metadata if it is a list
|
| 57 |
+
return self.metadata[:limit]
|