lmcuong199 commited on
Commit
1569ead
·
verified ·
1 Parent(s): 8ee75e7

Update recommendation_module.py

Browse files
Files changed (1) hide show
  1. recommendation_module.py +60 -1
recommendation_module.py CHANGED
@@ -132,4 +132,63 @@ def get_recommendation(
132
  else:
133
  size_label = "large"
134
 
135
- # Build query te
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  else:
133
  size_label = "large"
134
 
135
+ # Build query text — Sentence Transformer sẽ tìm case tương tự nhất
136
+ query_text = (
137
+ f"{site_type} ecotourism site, {size_label} size, "
138
+ f"{visitor_count} visitors per day, {risk_level} waste risk. "
139
+ f"Needs waste management improvement for sustainability certification."
140
+ )
141
+
142
+ # AI similarity search
143
+ model = get_model()
144
+ query_embedding = model.encode(query_text, convert_to_tensor=True)
145
+ case_embeddings = get_case_embeddings()
146
+ similarities = util.cos_sim(query_embedding, case_embeddings)[0]
147
+
148
+ # Top 1 match
149
+ best_idx = int(torch.argmax(similarities))
150
+ best_case = CASES[best_idx]
151
+ best_sim = float(similarities[best_idx])
152
+
153
+ # All scores sorted
154
+ scored = sorted(
155
+ zip(CASES, similarities.tolist()),
156
+ key=lambda x: -x[1]
157
+ )
158
+ rows = "\n".join([
159
+ f"| {c['name']} | {s:.1%} |"
160
+ for c, s in scored
161
+ ])
162
+
163
+ output = f"""## 💡 Recommendation for your site
164
+
165
+ **Query:** {query_text}
166
+
167
+ **Most Similar Certified Site:** {best_case['name']} (similarity: {best_sim:.1%})
168
+
169
+ ---
170
+
171
+ ### 📋 3-Phase Action Roadmap
172
+
173
+ **Phase 1 — Immediate (within 24 hours)**
174
+ {best_case['rec_immediate']}
175
+
176
+ **Phase 2 — Short Term (this month)**
177
+ {best_case['rec_monthly']}
178
+
179
+ **Phase 3 — Long Term (6-12 months)**
180
+ {best_case['rec_longterm']}
181
+
182
+ ---
183
+
184
+ ### ✅ Proven Result from Similar Site
185
+ {best_case['result']}
186
+
187
+ ---
188
+
189
+ ### Similarity Scores (All Reference Sites)
190
+ | Site | Similarity |
191
+ |------|-----------|
192
+ {rows}
193
+ """
194
+ return output, combined_risk