Spaces:
Sleeping
Sleeping
Create app.py
Browse files
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()
|