Skip to content

Commit

Permalink
[Week3]Feat: Modify main.py(#13)
Browse files Browse the repository at this point in the history
Add get_normal_recommendation api
  • Loading branch information
JM KIM committed Jan 30, 2023
1 parent 3bbf684 commit 67f99f8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions model_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
mask.paste(icon,icon)
mask = np.array(mask)

class Options(BaseModel):
living : Optional[int] = None
family : Optional[int] = None
area : Optional[int] = None
style : Optional[int] = None

def from_image_to_bytes(img):
"""
pillow image 객체를 bytes로 변환
Expand Down Expand Up @@ -83,6 +89,30 @@ def get_wordcloud(item_id: int = Query(None), split: int = Query(None)):

return '리뷰가 존재하지 않습니다.'

@app.get('/recommend/normal', description='get normal recommendation')
def get_normal_recommendation(filters : Options):
product_si = pd.read_csv("data/side_info.csv")

star_avg_df = data2.groupby(by=['item_id:token'], as_index=False)['star_avg:float'].mean()
star_avg_items = star_avg_df.loc[star_avg_df['star_avg:float'] > 4.63, 'item_id:token'].tolist()

cnt_df = data2.groupby(by=['item_id:token'], as_index=False)['user_id:token'].count()
basic_items = cnt_df.loc[cnt_df['user_id:token'] > 100]['item_id:token'].tolist()

random_items = list(set(star_avg_items).intersection(set(basic_items)))
if not (filters.living and filters.area and filters.family and filters.style):
selected_items = random.sample(random_items, 10)
recommend = product_si.loc[product_si['item_id'].isin(selected_items)]
item_info = get_item_info(recommend)

return {
'item_ids' : item_info[0],
'img_urls' : item_info[1],
'original_prices' : item_info[2],
'selling_prices' : item_info[3],
'titles' : item_info[4],
}

@app.get('/recommend/similar/item', description='get simlilar item')
def get_similar_item(item_id: int = Query(None), top_k: int = Query(None)):
from gensim.models import Word2Vec
Expand Down

0 comments on commit 67f99f8

Please sign in to comment.