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): 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 Book_title gr.ChatInterface( fn=recommend, textbox=gr.Textbox(placeholder="말걸어주세요..", container=False, scale=7), title="어떤 챗봇을 원하심미까?", description="물어보면 답하는 챗봇임미다.", theme="soft", examples=[["안뇽"], ["요즘 덥다 ㅠㅠ"], ["점심메뉴 추천바람, 짜장 짬뽕 택 1"]], retry_btn="다시보내기 ↩", undo_btn="이전챗 삭제 ❌", clear_btn="전챗 삭제 💫").launch() # gr.Interface( # fn=response, # title=title, # description=description, # examples=examples, # inputs=["text", "state"], # outputs=["chatbot", "state"], # theme="finlaymacklon/boxy_violet", # ).launch()