Spaces:
Sleeping
Sleeping
๊ฐ๋ฏผ๊ท commited on
Commit ยท
96a4d11
1
Parent(s): dbcc2a1
Add /recipes endpoint for list all recipes
Browse files- src/api.py +22 -0
src/api.py
CHANGED
|
@@ -56,6 +56,28 @@ def health_check():
|
|
| 56 |
status = "loading" if logic.df is None else "ok"
|
| 57 |
return {"status": status, "service": "K-Recipe2Vec API"}
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
@app.get("/recipes/search")
|
| 60 |
def search_recipes(q: str):
|
| 61 |
"""์๋ฆฌ๋ช
์ผ๋ก ๋ ์ํผ ๊ฒ์"""
|
|
|
|
| 56 |
status = "loading" if logic.df is None else "ok"
|
| 57 |
return {"status": status, "service": "K-Recipe2Vec API"}
|
| 58 |
|
| 59 |
+
@app.get("/recipes")
|
| 60 |
+
def list_recipes(limit: int = 50, offset: int = 0):
|
| 61 |
+
"""์ ์ฒด ๋ ์ํผ ๋ชฉ๋ก ์กฐํ (ํ์ด์ง๋ค์ด์
)"""
|
| 62 |
+
logic.ensure_initialized()
|
| 63 |
+
|
| 64 |
+
try:
|
| 65 |
+
total = len(logic.df)
|
| 66 |
+
subset = logic.df.iloc[offset:offset+limit][['๋ ์ํผ์ผ๋ จ๋ฒํธ', '์๋ฆฌ๋ช
', '์ฌ๋ฃํ ํฐ', '์๋ฆฌ๋ฐฉ๋ฒ๋ณ๋ช
', '์๋ฆฌ์ข
๋ฅ๋ณ๋ช
_์ธ๋ถํ']]
|
| 67 |
+
|
| 68 |
+
output = []
|
| 69 |
+
for _, row in subset.iterrows():
|
| 70 |
+
output.append({
|
| 71 |
+
"id": int(row['๋ ์ํผ์ผ๋ จ๋ฒํธ']),
|
| 72 |
+
"name": row['์๋ฆฌ๋ช
'],
|
| 73 |
+
"ingredients": row['์ฌ๋ฃํ ํฐ'],
|
| 74 |
+
"method": row['์๋ฆฌ๋ฐฉ๋ฒ๋ณ๋ช
'],
|
| 75 |
+
"category": row['์๋ฆฌ์ข
๋ฅ๋ณ๋ช
_์ธ๋ถํ']
|
| 76 |
+
})
|
| 77 |
+
return {"total": total, "recipes": output}
|
| 78 |
+
except Exception as e:
|
| 79 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 80 |
+
|
| 81 |
@app.get("/recipes/search")
|
| 82 |
def search_recipes(q: str):
|
| 83 |
"""์๋ฆฌ๋ช
์ผ๋ก ๋ ์ํผ ๊ฒ์"""
|