File size: 980 Bytes
56f1953
4a7c6e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56f1953
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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')

def response(message):
  embedding = model.encode(message)
  df['distance'] = df['embedding'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
  answer = df.loc[df['distance'].idxmax()]
  Book_title = answer['제λͺ©']
  Book_author = answer['μž‘κ°€']
  Book_publisher = answer['μΆœνŒμ‚¬']
  Book_comment = answer['μ„œν‰']
  return print(message)


gr.Interface(
    fn=predict,
    title=title,
    description=description,
    examples=examples,
    inputs=["text", "state"],
    outputs=["chatbot", "state"],
    theme="finlaymacklon/boxy_violet",
).launch()