Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,25 @@
|
|
1 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
# generate a response
|
25 |
-
history = model.generate(
|
26 |
-
bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id
|
27 |
-
).tolist()
|
28 |
-
|
29 |
-
# convert the tokens to text, and then split the responses into lines
|
30 |
-
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
31 |
-
# print('decoded_response-->>'+str(response))
|
32 |
-
response = [
|
33 |
-
(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)
|
34 |
-
] # convert to tuples of list
|
35 |
-
# print('response-->>'+str(response))
|
36 |
-
return response, history
|
37 |
|
38 |
|
39 |
gr.Interface(
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
import pandas as pd
|
4 |
+
from sentence_transformers import SentenceTransformer
|
5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
+
|
7 |
+
title = "๐๊ณ ๋ฏผ ํด๊ฒฐ ๋์ ์ถ์ฒ ์ฑ๋ด๐"
|
8 |
+
description = "๊ณ ๋ฏผ์ด ๋ฌด์์ธ๊ฐ์? ๊ณ ๋ฏผ ํด๊ฒฐ์ ๋์์ค ์ฑ
์ ์ถ์ฒํด๋๋ฆฝ๋๋ค"
|
9 |
+
examples = [["์์ฆ ์ ์ด ์ ์จ๋ค"]]
|
10 |
+
|
11 |
+
|
12 |
+
model = SentenceTransformer('jhgan/ko-sroberta-multitask')
|
13 |
+
|
14 |
+
def response(message):
|
15 |
+
embedding = model.encode(message)
|
16 |
+
df['distance'] = df['embedding'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
|
17 |
+
answer = df.loc[df['distance'].idxmax()]
|
18 |
+
Book_title = answer['์ ๋ชฉ']
|
19 |
+
Book_author = answer['์๊ฐ']
|
20 |
+
Book_publisher = answer['์ถํ์ฌ']
|
21 |
+
Book_comment = answer['์ํ']
|
22 |
+
return print(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
|
25 |
gr.Interface(
|