gamza commited on
Commit
4db9a76
โ€ข
1 Parent(s): 464eee8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from sentence_transformers import SentenceTransformer
4
+ 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()