File size: 1,323 Bytes
4db9a76
 
 
 
 
 
 
c2ab7a7
4db9a76
 
c2ab7a7
4db9a76
 
 
 
 
 
9aa7039
c2ab7a7
 
 
 
 
 
 
d16378b
4db9a76
 
 
 
c2ab7a7
 
4db9a76
c2ab7a7
4db9a76
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import pandas as pd
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity

title = "๐Ÿ€๊ณ ๋ฏผ ํ•ด๊ฒฐ ๋„์„œ ์ถ”์ฒœ ์ฑ—๋ด‡๐Ÿ€"
description = "๊ณ ๋ฏผ์ด ๋ฌด์—‡์ธ๊ฐ€์š”? ๊ณ ๋ฏผ ํ•ด๊ฒฐ์„ ๋„์™€์ค„ ์ฑ…์„ ์ถ”์ฒœํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค"
examples = [["์š”์ฆ˜ ์ž ์ด ์•ˆ ์˜จ๋‹ค"], ["ํ™”๋ถ„์ด ์ž˜ ์ž๋ผ์ง€ ์•Š์•„"]]


# model = SentenceTransformer('jhgan/ko-sroberta-multitask')

df = pd.read_pickle('BookData_emb.pkl')
df_emb = df[['์„œํ‰์ž„๋ฒ ๋”ฉ']].copy()


def recommend(message):
    answer = df.loc[df_emb['์„œํ‰์ž„๋ฒ ๋”ฉ'][0]]
  # embedding = model.encode(message)
  # df_emb['๊ฑฐ๋ฆฌ'] = df_emb['์„œํ‰์ž„๋ฒ ๋”ฉ'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
  # answer = df.loc[df_emb['๊ฑฐ๋ฆฌ'].idxmax()]
  # Book_title = answer['์ œ๋ชฉ']
  # Book_author = answer['์ž‘๊ฐ€']
  # Book_publisher = answer['์ถœํŒ์‚ฌ']
  # Book_comment = answer['์„œํ‰']
    return answer

gr.ChatInterface(
        fn=recommend,
        textbox=gr.Textbox(placeholder="๋ง๊ฑธ์–ด์ฃผ์„ธ์š”..", container=False, scale=7),
        title=title,
        description=description,
        theme="soft",
        examples=examples,
        retry_btn="๋‹ค์‹œ๋ณด๋‚ด๊ธฐ โ†ฉ",
        undo_btn="์ด์ „์ฑ— ์‚ญ์ œ โŒ",
        clear_btn="์ „์ฑ— ์‚ญ์ œ ๐Ÿ’ซ").launch()