Spaces:
Sleeping
Sleeping
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() |