Update app/routes.py
Browse files- app/routes.py +5 -2
app/routes.py
CHANGED
|
@@ -15,9 +15,12 @@ logging.basicConfig(level=logging.INFO)
|
|
| 15 |
# Load data and model once
|
| 16 |
df_cosing, df_brand, product_embeddings = load_data()
|
| 17 |
|
| 18 |
-
# Fungsi untuk membersihkan prefix seperti "Ingredients:", "Komposisi:", dll
|
| 19 |
def clean_ingredient_name(name):
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
@analyze_blueprint.route("/analyze", methods=["POST"])
|
| 23 |
def analyze_ingredients():
|
|
|
|
| 15 |
# Load data and model once
|
| 16 |
df_cosing, df_brand, product_embeddings = load_data()
|
| 17 |
|
|
|
|
| 18 |
def clean_ingredient_name(name):
|
| 19 |
+
# Hapus awalan seperti "Ingredients:", "Komposisi-", "Composition/", dll
|
| 20 |
+
name = re.sub(r'(?i)\b(ingredients|komposisi|composition|bahan)\b\s*[:/\-]?\s*', '', name)
|
| 21 |
+
# Hapus simbol-simbol aneh di awal (seperti '/', '-', ':', dll)
|
| 22 |
+
name = re.sub(r'^[^\w]+', '', name)
|
| 23 |
+
return name.strip()
|
| 24 |
|
| 25 |
@analyze_blueprint.route("/analyze", methods=["POST"])
|
| 26 |
def analyze_ingredients():
|