Spaces:
Runtime error
Runtime error
Download app.py from S2gamzaS2/chatbot_test: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/S2gamzaS2/chatbot_test/resolve/main/app.py
- Command line
-
hf download hf://spaces/S2gamzaS2/chatbot_test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/S2gamzaS2/chatbot_test/resolve/main/app.py
1.32 kB
| 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): | |
| answer = df.loc[df_emb['์ํ์๋ฒ ๋ฉ'][0]] | |
| # 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 answer | |
| gr.ChatInterface( | |
| fn=recommend, | |
| textbox=gr.Textbox(placeholder="๋ง๊ฑธ์ด์ฃผ์ธ์..", container=False, scale=7), | |
| title=title, | |
| description=description, | |
| theme="soft", | |
| examples=examples, | |
| retry_btn="๋ค์๋ณด๋ด๊ธฐ โฉ", | |
| undo_btn="์ด์ ์ฑ ์ญ์ โ", | |
| clear_btn="์ ์ฑ ์ญ์ ๐ซ").launch() |