gamza commited on
Commit
e3724eb
โ€ข
1 Parent(s): 14750f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,20 +1,27 @@
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
- def response(message, history):
14
- return message
 
 
 
 
 
 
 
15
 
16
  gr.ChatInterface(
17
- fn=response,
18
  textbox=gr.Textbox(placeholder="๋ง๊ฑธ์–ด์ฃผ์„ธ์š”..", container=False, scale=7),
19
  title="์–ด๋–ค ์ฑ—๋ด‡์„ ์›ํ•˜์‹ฌ๋ฏธ๊นŒ?",
20
  description="๋ฌผ์–ด๋ณด๋ฉด ๋‹ตํ•˜๋Š” ์ฑ—๋ด‡์ž„๋ฏธ๋‹ค.",
 
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
+ def recommend(message):
14
+ embedding = model.encode(message)
15
+ df_emb['๊ฑฐ๋ฆฌ'] = df_emb['์„œํ‰์ž„๋ฒ ๋”ฉ'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
16
+ answer = df.loc[df_emb['๊ฑฐ๋ฆฌ'].idxmax()]
17
+ Book_title = answer['์ œ๋ชฉ']
18
+ Book_author = answer['์ž‘๊ฐ€']
19
+ Book_publisher = answer['์ถœํŒ์‚ฌ']
20
+ Book_comment = answer['์„œํ‰']
21
+ return Book_title
22
 
23
  gr.ChatInterface(
24
+ fn=recommend,
25
  textbox=gr.Textbox(placeholder="๋ง๊ฑธ์–ด์ฃผ์„ธ์š”..", container=False, scale=7),
26
  title="์–ด๋–ค ์ฑ—๋ด‡์„ ์›ํ•˜์‹ฌ๋ฏธ๊นŒ?",
27
  description="๋ฌผ์–ด๋ณด๋ฉด ๋‹ตํ•˜๋Š” ์ฑ—๋ด‡์ž„๋ฏธ๋‹ค.",