Zaious commited on
Commit
1a17393
·
verified ·
1 Parent(s): 7009af2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -142,6 +142,16 @@ def analyze_query_and_find_products(query: str) -> str:
142
  print(ingredients)
143
  print("=======")
144
  # Generate embedding for the query
 
 
 
 
 
 
 
 
 
 
145
  query_embedding = get_embedding(query + " " + description)
146
 
147
  # Find similar products
@@ -155,24 +165,26 @@ def analyze_query_and_find_products(query: str) -> str:
155
  "\n📦 相關商品推薦:\n"
156
  ]
157
 
158
- for _, row in matching_products.iterrows():
159
- product_info = f"""
 
 
160
  • {row['item_name']}
161
- 分類: {row['tags']}
162
  描述: {row['description']}
 
 
163
  相似度: {row['similarity']:.2f}"""
164
- response_parts.append(product_info)
165
-
166
  response_parts.append("\n💡 購物建議:")
167
  response_parts.append("根據您的需求,以上是推薦的商品!")
168
 
169
  return "\n".join(response_parts)
170
-
171
  except Exception as e:
172
  print(f"Error in search: {str(e)}")
173
  return f"搜尋發生錯誤: {str(e)}"
174
 
175
-
176
  # Get system status
177
  def get_system_status():
178
  """Get system initialization status"""
 
142
  print(ingredients)
143
  print("=======")
144
  # Generate embedding for the query
145
+
146
+ # 為每個食材生成嵌入並進行查詢
147
+ search_results = []
148
+ for item in ingredients:
149
+ print(f"正在搜尋:{item}")
150
+ query_embedding = get_embedding(query + " " + item) # 生成食材嵌入
151
+ matching_products = find_similar_products(query_embedding) # 搜索結果
152
+ search_results.append((item, matching_products))
153
+
154
+
155
  query_embedding = get_embedding(query + " " + description)
156
 
157
  # Find similar products
 
165
  "\n📦 相關商品推薦:\n"
166
  ]
167
 
168
+ for item, matching_products in search_results:
169
+ response_parts.append(f"### {item} 的推薦商品:")
170
+ for _, row in matching_products.iterrows():
171
+ product_info = f"""
172
  • {row['item_name']}
 
173
  描述: {row['description']}
174
+ 分類: {row['tags']}
175
+ 規格: {row['spec']}
176
  相似度: {row['similarity']:.2f}"""
177
+ response_parts.append(product_info)
178
+
179
  response_parts.append("\n💡 購物建議:")
180
  response_parts.append("根據您的需求,以上是推薦的商品!")
181
 
182
  return "\n".join(response_parts)
183
+
184
  except Exception as e:
185
  print(f"Error in search: {str(e)}")
186
  return f"搜尋發生錯誤: {str(e)}"
187
 
 
188
  # Get system status
189
  def get_system_status():
190
  """Get system initialization status"""