Spaces:
Sleeping
Sleeping
๊ฐ๋ฏผ๊ท commited on
Commit ยท
aa1a383
1
Parent(s): 96a4d11
Add stopword filtering to recipe ingredients
Browse files- src/api.py +23 -3
src/api.py
CHANGED
|
@@ -48,6 +48,26 @@ def startup_event():
|
|
| 48 |
# ๋ฐฑ๊ทธ๋ผ์ด๋ ์ค๋ ๋์์ ๋ชจ๋ธ ๋ก๋ฉ ์์ (์ฑ ์์์ ๋ง์ง ์์)
|
| 49 |
threading.Thread(target=logic.load_resources).start()
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# --- Endpoints ---
|
| 52 |
|
| 53 |
@app.get("/")
|
|
@@ -70,7 +90,7 @@ def list_recipes(limit: int = 50, offset: int = 0):
|
|
| 70 |
output.append({
|
| 71 |
"id": int(row['๋ ์ํผ์ผ๋ จ๋ฒํธ']),
|
| 72 |
"name": row['์๋ฆฌ๋ช
'],
|
| 73 |
-
"ingredients": row['์ฌ๋ฃํ ํฐ'],
|
| 74 |
"method": row['์๋ฆฌ๋ฐฉ๋ฒ๋ณ๋ช
'],
|
| 75 |
"category": row['์๋ฆฌ์ข
๋ฅ๋ณ๋ช
_์ธ๋ถํ']
|
| 76 |
})
|
|
@@ -93,7 +113,7 @@ def search_recipes(q: str):
|
|
| 93 |
output.append({
|
| 94 |
"id": int(row['๋ ์ํผ์ผ๋ จ๋ฒํธ']),
|
| 95 |
"name": row['์๋ฆฌ๋ช
'],
|
| 96 |
-
"ingredients": row['์ฌ๋ฃํ ํฐ']
|
| 97 |
})
|
| 98 |
return output
|
| 99 |
except Exception as e:
|
|
@@ -115,7 +135,7 @@ def get_recipe_detail(recipe_id: int):
|
|
| 115 |
"name": row['์๋ฆฌ๋ช
'],
|
| 116 |
"method": row['์๋ฆฌ๋ฐฉ๋ฒ๋ณ๋ช
'],
|
| 117 |
"category": row['์๋ฆฌ์ข
๋ฅ๋ณ๋ช
_์ธ๋ถํ'],
|
| 118 |
-
"ingredients": row['์ฌ๋ฃํ ํฐ']
|
| 119 |
}
|
| 120 |
except Exception as e:
|
| 121 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 48 |
# ๋ฐฑ๊ทธ๋ผ์ด๋ ์ค๋ ๋์์ ๋ชจ๋ธ ๋ก๋ฉ ์์ (์ฑ ์์์ ๋ง์ง ์์)
|
| 49 |
threading.Thread(target=logic.load_resources).start()
|
| 50 |
|
| 51 |
+
# --- ๋ถ์ฉ์ด ์บ์ ๋ฐ ํํฐ๋ง ---
|
| 52 |
+
_stopwords_cache = None
|
| 53 |
+
|
| 54 |
+
def get_stopwords():
|
| 55 |
+
"""๋ถ์ฉ์ด ๋ชฉ๋ก์ ์บ์ํ์ฌ ๋ฐํ"""
|
| 56 |
+
global _stopwords_cache
|
| 57 |
+
if _stopwords_cache is None:
|
| 58 |
+
try:
|
| 59 |
+
_stopwords_cache = set(logic.load_global_stopwords())
|
| 60 |
+
except:
|
| 61 |
+
_stopwords_cache = set()
|
| 62 |
+
return _stopwords_cache
|
| 63 |
+
|
| 64 |
+
def filter_ingredients(ingredients_list):
|
| 65 |
+
"""์ฌ๋ฃ ๋ชฉ๋ก์์ ๋ถ์ฉ์ด ์ ๊ฑฐ"""
|
| 66 |
+
stopwords = get_stopwords()
|
| 67 |
+
if not stopwords:
|
| 68 |
+
return ingredients_list
|
| 69 |
+
return [ing for ing in ingredients_list if ing not in stopwords]
|
| 70 |
+
|
| 71 |
# --- Endpoints ---
|
| 72 |
|
| 73 |
@app.get("/")
|
|
|
|
| 90 |
output.append({
|
| 91 |
"id": int(row['๋ ์ํผ์ผ๋ จ๋ฒํธ']),
|
| 92 |
"name": row['์๋ฆฌ๋ช
'],
|
| 93 |
+
"ingredients": filter_ingredients(row['์ฌ๋ฃํ ํฐ']),
|
| 94 |
"method": row['์๋ฆฌ๋ฐฉ๋ฒ๋ณ๋ช
'],
|
| 95 |
"category": row['์๋ฆฌ์ข
๋ฅ๋ณ๋ช
_์ธ๋ถํ']
|
| 96 |
})
|
|
|
|
| 113 |
output.append({
|
| 114 |
"id": int(row['๋ ์ํผ์ผ๋ จ๋ฒํธ']),
|
| 115 |
"name": row['์๋ฆฌ๋ช
'],
|
| 116 |
+
"ingredients": filter_ingredients(row['์ฌ๋ฃํ ํฐ'])
|
| 117 |
})
|
| 118 |
return output
|
| 119 |
except Exception as e:
|
|
|
|
| 135 |
"name": row['์๋ฆฌ๋ช
'],
|
| 136 |
"method": row['์๋ฆฌ๋ฐฉ๋ฒ๋ณ๋ช
'],
|
| 137 |
"category": row['์๋ฆฌ์ข
๋ฅ๋ณ๋ช
_์ธ๋ถํ'],
|
| 138 |
+
"ingredients": filter_ingredients(row['์ฌ๋ฃํ ํฐ'])
|
| 139 |
}
|
| 140 |
except Exception as e:
|
| 141 |
raise HTTPException(status_code=500, detail=str(e))
|