gamza commited on
Commit
ba99c5c
โ€ข
1 Parent(s): c2cf52d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -25
app.py CHANGED
@@ -1,32 +1,40 @@
1
  import gradio as gr
2
- import pandas as pd
3
- from sentence_transformers import SentenceTransformer
4
- from sklearn.metrics.pairwise import cosine_similarity
5
 
6
- title = "๐Ÿ€๊ณ ๋ฏผ ํ•ด๊ฒฐ ๋„์„œ ์ถ”์ฒœ ์ฑ—๋ด‡๐Ÿ€"
7
- description = "๊ณ ๋ฏผ์ด ๋ฌด์—‡์ธ๊ฐ€์š”? ๊ณ ๋ฏผ ํ•ด๊ฒฐ์„ ๋„์™€์ค„ ์ฑ…์„ ์ถ”์ฒœํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค"
8
- examples = [["์š”์ฆ˜ ์ž ์ด ์•ˆ ์˜จ๋‹ค"]]
9
 
10
 
11
- model = SentenceTransformer('jhgan/ko-sroberta-multitask')
12
 
13
- def response(message):
14
- embedding = model.encode(message)
15
- df['distance'] = df['embedding'].map(lambda x: cosine_similarity([embedding], [x]).squeeze())
16
- answer = df.loc[df['distance'].idxmax()]
17
- Book_title = answer['์ œ๋ชฉ']
18
- Book_author = answer['์ž‘๊ฐ€']
19
- Book_publisher = answer['์ถœํŒ์‚ฌ']
20
- Book_comment = answer['์„œํ‰']
21
- return print(message)
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- gr.Interface(
25
- fn=response,
26
- title=title,
27
- description=description,
28
- examples=examples,
29
- inputs=["text", "state"],
30
- outputs=["chatbot", "state"],
31
- theme="finlaymacklon/boxy_violet",
32
- ).launch()
 
1
  import gradio as gr
2
+ # import pandas as pd
3
+ # from sentence_transformers import SentenceTransformer
4
+ # from sklearn.metrics.pairwise import cosine_similarity
5
 
6
+ # title = "๐Ÿ€๊ณ ๋ฏผ ํ•ด๊ฒฐ ๋„์„œ ์ถ”์ฒœ ์ฑ—๋ด‡๐Ÿ€"
7
+ # description = "๊ณ ๋ฏผ์ด ๋ฌด์—‡์ธ๊ฐ€์š”? ๊ณ ๋ฏผ ํ•ด๊ฒฐ์„ ๋„์™€์ค„ ์ฑ…์„ ์ถ”์ฒœํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค"
8
+ # examples = [["์š”์ฆ˜ ์ž ์ด ์•ˆ ์˜จ๋‹ค"]]
9
 
10
 
11
+ # model = SentenceTransformer('jhgan/ko-sroberta-multitask')
12
 
13
+ def response(message, history, additional_input_info):
14
+ # additional_input_info์˜ ํ…์ŠคํŠธ๋ฅผ ์ฑ—๋ด‡์˜ ๋Œ€๋‹ต ๋’ค์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
15
+ return "์ฑ—๋ด‡์„ ๋ฏธ์™„์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค " + additional_input_info
 
 
 
 
 
 
16
 
17
+ gr.ChatInterface(
18
+ fn=response,
19
+ textbox=gr.Textbox(placeholder="๋ง๊ฑธ์–ด์ฃผ์„ธ์š”..", container=False, scale=7),
20
+ title="์–ด๋–ค ์ฑ—๋ด‡์„ ์›ํ•˜์‹ฌ๋ฏธ๊นŒ?",
21
+ description="๋ฌผ์–ด๋ณด๋ฉด ๋‹ตํ•˜๋Š” ์ฑ—๋ด‡์ž„๋ฏธ๋‹ค.",
22
+ theme="soft",
23
+ examples=[["์•ˆ๋‡ฝ"], ["์š”์ฆ˜ ๋ฅ๋‹ค ใ… ใ… "], ["์ ์‹ฌ๋ฉ”๋‰ด ์ถ”์ฒœ๋ฐ”๋žŒ, ์งœ์žฅ ์งฌ๋ฝ• ํƒ 1"]],
24
+ retry_btn="๋‹ค์‹œ๋ณด๋‚ด๊ธฐ โ†ฉ",
25
+ undo_btn="์ด์ „์ฑ— ์‚ญ์ œ โŒ",
26
+ clear_btn="์ „์ฑ— ์‚ญ์ œ ๐Ÿ’ซ",
27
+ additional_inputs=[
28
+ gr.Textbox("!!!", label="๋๋ง์ž‡๊ธฐ")
29
+ ]
30
+ ).launch()
31
 
32
+ # gr.Interface(
33
+ # fn=response,
34
+ # title=title,
35
+ # description=description,
36
+ # examples=examples,
37
+ # inputs=["text", "state"],
38
+ # outputs=["chatbot", "state"],
39
+ # theme="finlaymacklon/boxy_violet",
40
+ # ).launch()