File size: 993 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
33
import gradio as gr
import torch
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()