chatbot_test / app.py
gamza's picture
Update app.py
d16378b
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()