gamza commited on
Commit
c2ab7a7
ยท
1 Parent(s): 24f7ce0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -5,32 +5,33 @@ from sklearn.metrics.pairwise import cosine_similarity
5
 
6
  title = "๐Ÿ€๊ณ ๋ฏผ ํ•ด๊ฒฐ ๋„์„œ ์ถ”์ฒœ ์ฑ—๋ด‡๐Ÿ€"
7
  description = "๊ณ ๋ฏผ์ด ๋ฌด์—‡์ธ๊ฐ€์š”? ๊ณ ๋ฏผ ํ•ด๊ฒฐ์„ ๋„์™€์ค„ ์ฑ…์„ ์ถ”์ฒœํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค"
8
- examples = [["์š”์ฆ˜ ์ž ์ด ์•ˆ ์˜จ๋‹ค"]]
9
 
10
 
11
- model = SentenceTransformer('jhgan/ko-sroberta-multitask')
12
 
13
  df = pd.read_pickle('BookData_emb.pkl')
14
  df_emb = df[['์„œํ‰์ž„๋ฒ ๋”ฉ']].copy()
15
 
16
 
17
  def recommend(message):
18
- embedding = model.encode(message)
19
- df_emb['๊ฑฐ๋ฆฌ'] = df_emb['์„œํ‰์ž„๋ฒ ๋”ฉ'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
20
- answer = df.loc[df_emb['๊ฑฐ๋ฆฌ'].idxmax()]
21
- Book_title = answer['์ œ๋ชฉ']
22
- Book_author = answer['์ž‘๊ฐ€']
23
- Book_publisher = answer['์ถœํŒ์‚ฌ']
24
- Book_comment = answer['์„œํ‰']
25
- return Book_title
 
26
 
27
  gr.ChatInterface(
28
  fn=recommend,
29
  textbox=gr.Textbox(placeholder="๋ง๊ฑธ์–ด์ฃผ์„ธ์š”..", container=False, scale=7),
30
- title="์–ด๋–ค ์ฑ—๋ด‡์„ ์›ํ•˜์‹ฌ๋ฏธ๊นŒ?",
31
- description="๋ฌผ์–ด๋ณด๋ฉด ๋‹ตํ•˜๋Š” ์ฑ—๋ด‡์ž„๋ฏธ๋‹ค.",
32
  theme="soft",
33
- examples=[["์•ˆ๋‡ฝ"], ["์š”์ฆ˜ ๋ฅ๋‹ค ใ… ใ… "], ["์ ์‹ฌ๋ฉ”๋‰ด ์ถ”์ฒœ๋ฐ”๋žŒ, ์งœ์žฅ ์งฌ๋ฝ• ํƒ 1"]],
34
  retry_btn="๋‹ค์‹œ๋ณด๋‚ด๊ธฐ โ†ฉ",
35
  undo_btn="์ด์ „์ฑ— ์‚ญ์ œ โŒ",
36
  clear_btn="์ „์ฑ— ์‚ญ์ œ ๐Ÿ’ซ").launch()
 
5
 
6
  title = "๐Ÿ€๊ณ ๋ฏผ ํ•ด๊ฒฐ ๋„์„œ ์ถ”์ฒœ ์ฑ—๋ด‡๐Ÿ€"
7
  description = "๊ณ ๋ฏผ์ด ๋ฌด์—‡์ธ๊ฐ€์š”? ๊ณ ๋ฏผ ํ•ด๊ฒฐ์„ ๋„์™€์ค„ ์ฑ…์„ ์ถ”์ฒœํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค"
8
+ examples = [["์š”์ฆ˜ ์ž ์ด ์•ˆ ์˜จ๋‹ค"], ["ํ™”๋ถ„์ด ์ž˜ ์ž๋ผ์ง€ ์•Š์•„"]]
9
 
10
 
11
+ # model = SentenceTransformer('jhgan/ko-sroberta-multitask')
12
 
13
  df = pd.read_pickle('BookData_emb.pkl')
14
  df_emb = df[['์„œํ‰์ž„๋ฒ ๋”ฉ']].copy()
15
 
16
 
17
  def recommend(message):
18
+ text = df_emb['์„œํ‰์ž„๋ฒ ๋”ฉ'][0]
19
+ # embedding = model.encode(message)
20
+ # df_emb['๊ฑฐ๋ฆฌ'] = df_emb['์„œํ‰์ž„๋ฒ ๋”ฉ'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
21
+ # answer = df.loc[df_emb['๊ฑฐ๋ฆฌ'].idxmax()]
22
+ # Book_title = answer['์ œ๋ชฉ']
23
+ # Book_author = answer['์ž‘๊ฐ€']
24
+ # Book_publisher = answer['์ถœํŒ์‚ฌ']
25
+ # Book_comment = answer['์„œํ‰']
26
+ return message + text
27
 
28
  gr.ChatInterface(
29
  fn=recommend,
30
  textbox=gr.Textbox(placeholder="๋ง๊ฑธ์–ด์ฃผ์„ธ์š”..", container=False, scale=7),
31
+ title=title,
32
+ description=description,
33
  theme="soft",
34
+ examples=examples,
35
  retry_btn="๋‹ค์‹œ๋ณด๋‚ด๊ธฐ โ†ฉ",
36
  undo_btn="์ด์ „์ฑ— ์‚ญ์ œ โŒ",
37
  clear_btn="์ „์ฑ— ์‚ญ์ œ ๐Ÿ’ซ").launch()