Spaces:
Sleeping
Sleeping
Upload 164 files
Browse files- src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc +0 -0
- src/apis/controllers/__pycache__/post_controller.cpython-311.pyc +0 -0
- src/apis/controllers/destination_controller.py +61 -23
- src/apis/controllers/post_controller.py +31 -18
- src/apis/routes/__pycache__/travel_dest_route.cpython-311.pyc +0 -0
src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/destination_controller.cpython-311.pyc differ
|
|
|
src/apis/controllers/__pycache__/post_controller.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/controllers/__pycache__/post_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/post_controller.cpython-311.pyc differ
|
|
|
src/apis/controllers/destination_controller.py
CHANGED
|
@@ -66,27 +66,65 @@ async def destination_recommendation_func(
|
|
| 66 |
}
|
| 67 |
for i in output
|
| 68 |
]
|
| 69 |
-
return output
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
}
|
| 67 |
for i in output
|
| 68 |
]
|
| 69 |
+
return {"characteristic": output, "geoapify": []}
|
| 70 |
+
else:
|
| 71 |
+
import asyncio
|
| 72 |
+
|
| 73 |
+
# Define async tasks for both operations
|
| 74 |
+
async def get_geoapify_results():
|
| 75 |
+
characteristic_extract_response: CharacteristicExtractor = (
|
| 76 |
+
await characteristic_extractor_chain.ainvoke({"query": query})
|
| 77 |
+
)
|
| 78 |
+
lat, lon = get_lat_long_location(characteristic_extract_response.main_place)
|
| 79 |
+
response = get_places(
|
| 80 |
+
lat,
|
| 81 |
+
lon,
|
| 82 |
+
5000,
|
| 83 |
+
available_categories.get(characteristic_extract_response.kind, None),
|
| 84 |
+
top_k,
|
| 85 |
+
)
|
| 86 |
+
output_geo = json.loads(response.body)
|
| 87 |
+
if tool_chat:
|
| 88 |
+
output_geo = [
|
| 89 |
+
{
|
| 90 |
+
"name": i["name"],
|
| 91 |
+
"address": i["address"],
|
| 92 |
+
"distance_km": i["distance_km"],
|
| 93 |
+
}
|
| 94 |
+
for i in output_geo
|
| 95 |
+
]
|
| 96 |
+
return output_geo
|
| 97 |
+
|
| 98 |
+
async def get_characteristic_results():
|
| 99 |
+
output_characteristic = await destination_suggestion_controller(
|
| 100 |
+
query, user_id, top_k
|
| 101 |
+
)
|
| 102 |
+
output_characteristic = [
|
| 103 |
+
{
|
| 104 |
+
"name": i,
|
| 105 |
+
"map_url": "https://www.google.com/maps/search/109.23333,13.76667",
|
| 106 |
+
}
|
| 107 |
+
for i in output_characteristic
|
| 108 |
+
]
|
| 109 |
+
return output_characteristic
|
| 110 |
+
|
| 111 |
+
# Run both tasks concurrently
|
| 112 |
+
output_geo_task = asyncio.create_task(get_geoapify_results())
|
| 113 |
+
output_characteristic_task = asyncio.create_task(get_characteristic_results())
|
| 114 |
+
|
| 115 |
+
# Wait for both tasks to complete
|
| 116 |
+
output_geo, output_characteristic = await asyncio.gather(
|
| 117 |
+
output_geo_task, output_characteristic_task
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
# If tool_chat mode, return just the geoapify results
|
| 121 |
+
if tool_chat:
|
| 122 |
+
return output_geo
|
| 123 |
+
|
| 124 |
+
logger.info(f"output_geo {output_geo}")
|
| 125 |
+
logger.info(f"output_characteristic {output_characteristic}")
|
| 126 |
|
| 127 |
+
return {
|
| 128 |
+
"geoapify": output_geo,
|
| 129 |
+
"characteristic": output_characteristic,
|
| 130 |
+
}
|
src/apis/controllers/post_controller.py
CHANGED
|
@@ -9,6 +9,7 @@ from bson import ObjectId
|
|
| 9 |
import math
|
| 10 |
from src.utils.helper import deserialize_objectid
|
| 11 |
from typing import List
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
async def create_a_post_controller(
|
|
@@ -78,9 +79,13 @@ async def list_all_posts_controller_priority(
|
|
| 78 |
method="GET",
|
| 79 |
url=f"https://abao77-triventure-personalize.hf.space/model/get_recommendation_destinations/{user_id}/5",
|
| 80 |
)
|
| 81 |
-
top_5_destinations = response_recommendation_destinations.get(
|
|
|
|
|
|
|
| 82 |
# top_5_destinations = []
|
| 83 |
-
destinations_list = response_recommendation_destinations.get(
|
|
|
|
|
|
|
| 84 |
|
| 85 |
start_time = time.time()
|
| 86 |
PAGE_SIZE = 10
|
|
@@ -91,7 +96,6 @@ async def list_all_posts_controller_priority(
|
|
| 91 |
|
| 92 |
excluded_ids = [deserialize_objectid(pid) for pid in view_post_ids]
|
| 93 |
|
| 94 |
-
# Tạo filter cho 2 nhóm
|
| 95 |
top_filter = {
|
| 96 |
"destination_id": {"$in": top_5_destinations},
|
| 97 |
"_id": {"$nin": excluded_ids},
|
|
@@ -112,6 +116,7 @@ async def list_all_posts_controller_priority(
|
|
| 112 |
limit=TOP_LIMIT,
|
| 113 |
skip=skip_top,
|
| 114 |
)
|
|
|
|
| 115 |
|
| 116 |
other_posts = await PostCRUD.find_many_with_score(
|
| 117 |
filter=other_filter,
|
|
@@ -119,8 +124,6 @@ async def list_all_posts_controller_priority(
|
|
| 119 |
limit=OTHER_LIMIT,
|
| 120 |
skip=skip_other,
|
| 121 |
)
|
| 122 |
-
|
| 123 |
-
# Xen kẽ
|
| 124 |
combined_posts = []
|
| 125 |
i = j = 0
|
| 126 |
while len(combined_posts) < PAGE_SIZE and (
|
|
@@ -133,8 +136,15 @@ async def list_all_posts_controller_priority(
|
|
| 133 |
combined_posts.append(other_posts[j])
|
| 134 |
j += 1
|
| 135 |
|
| 136 |
-
user_ids = list(
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
post_ids = [serialize_datetime(post["_id"]) for post in combined_posts]
|
| 139 |
|
| 140 |
user_infos_result = await UserCRUD.read({"_id": {"$in": user_ids}})
|
|
@@ -242,13 +252,17 @@ async def list_all_posts_controller(user_id: str, page: int = 1):
|
|
| 242 |
|
| 243 |
# Get unique user and destination IDs
|
| 244 |
user_ids = list({deserialize_objectid(post.get("user_id")) for post in posts})
|
| 245 |
-
destination_ids = list(
|
| 246 |
-
|
|
|
|
|
|
|
| 247 |
# Use $in operator for batch lookups
|
| 248 |
user_infos = await UserCRUD.read({"_id": {"$in": user_ids}})
|
| 249 |
print("user_infos", user_infos)
|
| 250 |
-
destination_infos = await DestinationCRUD.read(
|
| 251 |
-
|
|
|
|
|
|
|
| 252 |
# Create user info map
|
| 253 |
user_info_map = {
|
| 254 |
info.get("_id"): {
|
|
@@ -259,20 +273,19 @@ async def list_all_posts_controller(user_id: str, page: int = 1):
|
|
| 259 |
for info in user_infos
|
| 260 |
if info
|
| 261 |
}
|
| 262 |
-
|
| 263 |
# Create destination info map
|
| 264 |
destination_info_map = {
|
| 265 |
info.get("_id"): info.get("name") for info in destination_infos if info
|
| 266 |
}
|
| 267 |
-
|
| 268 |
formatted_user_reactions_map = {}
|
| 269 |
if user_id:
|
| 270 |
all_post_ids = [serialize_datetime(post.get("_id")) for post in posts]
|
| 271 |
# Use $in operator for batch lookup of reactions
|
| 272 |
-
reactions = await ReactionCRUD.read(
|
| 273 |
-
"user_id": user_id,
|
| 274 |
-
|
| 275 |
-
})
|
| 276 |
for reaction in reactions:
|
| 277 |
if reaction:
|
| 278 |
post_id = reaction.get("post_id")
|
|
@@ -353,7 +366,7 @@ async def list_posts_by_destination_controller(
|
|
| 353 |
|
| 354 |
# Get unique user_ids
|
| 355 |
user_ids = list({deserialize_objectid(post.get("user_id")) for post in posts})
|
| 356 |
-
|
| 357 |
# Use $in operator for batch user lookup
|
| 358 |
user_infos = await UserCRUD.read({"_id": {"$in": user_ids}})
|
| 359 |
user_info_map = {
|
|
|
|
| 9 |
import math
|
| 10 |
from src.utils.helper import deserialize_objectid
|
| 11 |
from typing import List
|
| 12 |
+
import random
|
| 13 |
|
| 14 |
|
| 15 |
async def create_a_post_controller(
|
|
|
|
| 79 |
method="GET",
|
| 80 |
url=f"https://abao77-triventure-personalize.hf.space/model/get_recommendation_destinations/{user_id}/5",
|
| 81 |
)
|
| 82 |
+
top_5_destinations = response_recommendation_destinations.get(
|
| 83 |
+
"destination_ids", []
|
| 84 |
+
)
|
| 85 |
# top_5_destinations = []
|
| 86 |
+
destinations_list = response_recommendation_destinations.get(
|
| 87 |
+
"destinations_list", None
|
| 88 |
+
)
|
| 89 |
|
| 90 |
start_time = time.time()
|
| 91 |
PAGE_SIZE = 10
|
|
|
|
| 96 |
|
| 97 |
excluded_ids = [deserialize_objectid(pid) for pid in view_post_ids]
|
| 98 |
|
|
|
|
| 99 |
top_filter = {
|
| 100 |
"destination_id": {"$in": top_5_destinations},
|
| 101 |
"_id": {"$nin": excluded_ids},
|
|
|
|
| 116 |
limit=TOP_LIMIT,
|
| 117 |
skip=skip_top,
|
| 118 |
)
|
| 119 |
+
random.shuffle(top_posts)
|
| 120 |
|
| 121 |
other_posts = await PostCRUD.find_many_with_score(
|
| 122 |
filter=other_filter,
|
|
|
|
| 124 |
limit=OTHER_LIMIT,
|
| 125 |
skip=skip_other,
|
| 126 |
)
|
|
|
|
|
|
|
| 127 |
combined_posts = []
|
| 128 |
i = j = 0
|
| 129 |
while len(combined_posts) < PAGE_SIZE and (
|
|
|
|
| 136 |
combined_posts.append(other_posts[j])
|
| 137 |
j += 1
|
| 138 |
|
| 139 |
+
user_ids = list(
|
| 140 |
+
{deserialize_objectid(post.get("user_id")) for post in combined_posts}
|
| 141 |
+
)
|
| 142 |
+
destination_ids = list(
|
| 143 |
+
{
|
| 144 |
+
deserialize_objectid(post.get("destination_id"))
|
| 145 |
+
for post in combined_posts
|
| 146 |
+
}
|
| 147 |
+
)
|
| 148 |
post_ids = [serialize_datetime(post["_id"]) for post in combined_posts]
|
| 149 |
|
| 150 |
user_infos_result = await UserCRUD.read({"_id": {"$in": user_ids}})
|
|
|
|
| 252 |
|
| 253 |
# Get unique user and destination IDs
|
| 254 |
user_ids = list({deserialize_objectid(post.get("user_id")) for post in posts})
|
| 255 |
+
destination_ids = list(
|
| 256 |
+
{deserialize_objectid(post.get("destination_id")) for post in posts}
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
# Use $in operator for batch lookups
|
| 260 |
user_infos = await UserCRUD.read({"_id": {"$in": user_ids}})
|
| 261 |
print("user_infos", user_infos)
|
| 262 |
+
destination_infos = await DestinationCRUD.read(
|
| 263 |
+
{"_id": {"$in": destination_ids}}
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
# Create user info map
|
| 267 |
user_info_map = {
|
| 268 |
info.get("_id"): {
|
|
|
|
| 273 |
for info in user_infos
|
| 274 |
if info
|
| 275 |
}
|
| 276 |
+
|
| 277 |
# Create destination info map
|
| 278 |
destination_info_map = {
|
| 279 |
info.get("_id"): info.get("name") for info in destination_infos if info
|
| 280 |
}
|
| 281 |
+
|
| 282 |
formatted_user_reactions_map = {}
|
| 283 |
if user_id:
|
| 284 |
all_post_ids = [serialize_datetime(post.get("_id")) for post in posts]
|
| 285 |
# Use $in operator for batch lookup of reactions
|
| 286 |
+
reactions = await ReactionCRUD.read(
|
| 287 |
+
{"user_id": user_id, "post_id": {"$in": all_post_ids}}
|
| 288 |
+
)
|
|
|
|
| 289 |
for reaction in reactions:
|
| 290 |
if reaction:
|
| 291 |
post_id = reaction.get("post_id")
|
|
|
|
| 366 |
|
| 367 |
# Get unique user_ids
|
| 368 |
user_ids = list({deserialize_objectid(post.get("user_id")) for post in posts})
|
| 369 |
+
|
| 370 |
# Use $in operator for batch user lookup
|
| 371 |
user_infos = await UserCRUD.read({"_id": {"$in": user_ids}})
|
| 372 |
user_info_map = {
|
src/apis/routes/__pycache__/travel_dest_route.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/routes/__pycache__/travel_dest_route.cpython-311.pyc and b/src/apis/routes/__pycache__/travel_dest_route.cpython-311.pyc differ
|
|
|