Spaces:
Sleeping
Sleeping
Delete unused files
Browse files- README copy.md +0 -173
- README.md +1 -1
README copy.md
DELETED
|
@@ -1,173 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
<h2 align="center">
|
| 4 |
-
Streamlit Chatbot
|
| 5 |
-
</h2>
|
| 6 |
-
|
| 7 |
-
<div align="center">
|
| 8 |
-
<img src="https://img.shields.io/badge/python-v3.9.16-blue.svg"/>
|
| 9 |
-
<img src="https://img.shields.io/badge/streamlit-v1.20.0-blue.svg"/>
|
| 10 |
-
<img src="https://img.shields.io/badge/streamlit_chat-v0.0.2.2-blue.svg"/>
|
| 11 |
-
</div>
|
| 12 |
-
|
| 13 |
-
**streamlit-chat**์ Streamlit์ ์ด์ฉํ์ฌ ์ค์๊ฐ ๋ํํ Web ์ ํ๋ฆฌ์ผ์ด์
์ ์ฝ๊ฒ ๋ง๋ค ์ ์๋ ํจํค์ง์
๋๋ค. ๋ง๋๋ ๋ฐฉ๋ฒ์ ๋งค์ฐ ๊ฐ๋จํ๋ฉฐ [์์ ](https://share.streamlit.io/ai-yash/st-chat/main/examples/chatbot.py) ํ์ธ๋ ๊ฐ๋ฅํฉ๋๋ค.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
<div align="center">
|
| 18 |
-
<img src="https://blog.kakaocdn.net/dn/cACrfC/btr65p6tNGQ/kPoXKMh4LAmUtsuhGXOHOk/img.gif" width="70%">
|
| 19 |
-
</div>
|
| 20 |
-
|
| 21 |
-
streamlit-chat์ผ๋ก Hugging Face์์ ์ ๊ณตํ๋ Facebook AI BlenderBot๊ณผ OpenAI์ GPT-3 ๋ชจ๋ธ๋ก ์ฑ๋ด ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด ๋ณด๊ฒ ์ต๋๋ค.
|
| 22 |
-
|
| 23 |
-
------
|
| 24 |
-
|
| 25 |
-
### 1. ์ค์น (Installation)
|
| 26 |
-
|
| 27 |
-
streamlit๊ณผ streamlit-chat ํจํค์ง ์ค์น๋ pip ๋ช
๋ น์ด๋ฅผ ์ด์ฉํ์ฌ ์ค์นํ ์ ์์ต๋๋ค.
|
| 28 |
-
|
| 29 |
-
```bash
|
| 30 |
-
pip install streamlit
|
| 31 |
-
pip install streamlit-chat
|
| 32 |
-
```
|
| 33 |
-
|
| 34 |
-
streamlit ์ค์น์ ๊ด๋ จ๋ ๋ด์ฉ์ ์ด์ ๊ธ์ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.
|
| 35 |
-
|
| 36 |
-
[Streamlit ์์ํ๊ธฐ (์ค์น๋ฐฉ๋ฒ)](https://yunwoong.tistory.com/226)
|
| 37 |
-
|
| 38 |
-
### 2. BlenderBot ์ฑ๋ด
|
| 39 |
-
|
| 40 |
-
BlenderBot์ Hugging Face์ Transformers ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํ์ฌ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๋จผ์ Hugging Face Inference API Key ๋ฐ๊ธ์ ์งํํฉ๋๋ค. ์๋ ๊ธ์ ์ฐธ๊ณ ํ์ธ์.
|
| 41 |
-
|
| 42 |
-
[Hugging Face Inference API Key ๋ฐ๊ธ](https://yunwoong.tistory.com/225)
|
| 43 |
-
|
| 44 |
-
Python ํ์ผ blenderbot_app.py ์ ์์ฑํ๊ณ ์๋์ ๊ฐ์ด ์์ฑํฉ๋๋ค. API_TOKEN์ ์์ ์ Hugging Face Inference API Key ๋ฅผ ์
๋ ฅํฉ๋๋ค. (์: hf_xxxxxxxxxxxxxxxxxxxxx)
|
| 45 |
-
|
| 46 |
-
```python
|
| 47 |
-
import streamlit as st
|
| 48 |
-
from streamlit_chat import message
|
| 49 |
-
import requests
|
| 50 |
-
|
| 51 |
-
API_URL = "https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill"
|
| 52 |
-
API_TOKEN = "YOUR API TOKEN HERE"
|
| 53 |
-
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
| 54 |
-
|
| 55 |
-
st.header("๐คYunwoong's BlenderBot (Demo)")
|
| 56 |
-
st.markdown("[Be Original](https://yunwoong.tistory.com/)")
|
| 57 |
-
|
| 58 |
-
if 'generated' not in st.session_state:
|
| 59 |
-
st.session_state['generated'] = []
|
| 60 |
-
|
| 61 |
-
if 'past' not in st.session_state:
|
| 62 |
-
st.session_state['past'] = []
|
| 63 |
-
|
| 64 |
-
def query(payload):
|
| 65 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
| 66 |
-
return response.json()
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
with st.form('form', clear_on_submit=True):
|
| 70 |
-
user_input = st.text_input('You: ', '', key='input')
|
| 71 |
-
submitted = st.form_submit_button('Send')
|
| 72 |
-
|
| 73 |
-
if submitted and user_input:
|
| 74 |
-
output = query({
|
| 75 |
-
"inputs": {
|
| 76 |
-
"past_user_inputs": st.session_state.past,
|
| 77 |
-
"generated_responses": st.session_state.generated,
|
| 78 |
-
"text": user_input,
|
| 79 |
-
},
|
| 80 |
-
"parameters": {"repetition_penalty": 1.33},
|
| 81 |
-
})
|
| 82 |
-
|
| 83 |
-
st.session_state.past.append(user_input)
|
| 84 |
-
st.session_state.generated.append(output["generated_text"])
|
| 85 |
-
|
| 86 |
-
if st.session_state['generated']:
|
| 87 |
-
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
| 88 |
-
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
| 89 |
-
message(st.session_state["generated"][i], key=str(i))
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
ํฐ๋ฏธ๋์์ ์๋์ ๊ฐ์ด ์
๋ ฅํ๋ฉด Streamlit ์ฑ์ ์คํํฉ๋๋ค.
|
| 93 |
-
|
| 94 |
-
```bash
|
| 95 |
-
streamlit run blenderbot_app.py
|
| 96 |
-
```
|
| 97 |
-
|
| 98 |
-
<div align="center">
|
| 99 |
-
<img src="https://blog.kakaocdn.net/dn/nwBzi/btr7cISnZwI/JK6JWPNCeEUNtBGRShOGFK/img.gif" width="70%">
|
| 100 |
-
</div>
|
| 101 |
-
|
| 102 |
-
### 3. GPT-3 ์ฑ๋ด
|
| 103 |
-
|
| 104 |
-
๋ค์์ผ๋ก OpenAI API๋ฅผ ์ด์ฉํ GPT-3 ์ฑ๋ด์ ๋ง๋ค๋๋ก ํ๊ฒ ์ต๋๋ค.
|
| 105 |
-
|
| 106 |
-
๋จผ์ OpenAI API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด API ํค ๋ฐ๊ธ์ด ํ์ํฉ๋๋ค. ๋จผ์ [OpenAI API ์ฌ์ดํธ](https://platform.openai.com/)๋ก ์ด๋ํฉ๋๋ค. OpenAI ๊ณ์ ์ด ํ์ํ๋ฉฐ ๊ณ์ ์ด ์๋ค๋ฉด ๊ณ์ ์์ฑ์ด ํ์ํฉ๋๋ค. ๊ฐ๋จํ Google์ด๋ Microsoft ๊ณ์ ์ ์ฐ๋ ํ ์ ์์ต๋๋ค. ์ด๋ฏธ ๊ณ์ ์ด ์๋ค๋ฉด ๋ก๊ทธ์ธ ํ ์งํํ์๋ฉด ๋ฉ๋๋ค.
|
| 107 |
-
|
| 108 |
-
๋ก๊ทธ์ธ์ด ๋์๋ค๋ฉด ์ฐ์ธก ์๋จ Personal -> [ View API Keys ] ๋ฅผ ํด๋ฆญํฉ๋๋ค.
|
| 109 |
-
|
| 110 |
-

|
| 111 |
-
|
| 112 |
-
[ + Create new secret key ] ๋ฅผ ํด๋ฆญํ์ฌ API Key๋ฅผ ์์ฑํฉ๋๋ค. API key generated ์ฐฝ์ด ํ์ฑํ๋๋ฉด Key ๋ฅผ ๋ฐ๋์ ๋ณต์ฌํ์ฌ ๋์๊ธฐ ๋ฐ๋๋๋ค. ์ฐฝ์ ๋ซ์ผ๋ฉด ๋ค์ ํ์ธํ ์ ์์ต๋๋ค. (๋ง์ฝ ๋ณต์ฌํ์ง ๋ชปํ๋ค๋ฉด ๋ค์ Create new secret key ๋ฒํผ์ ๋๋ฌ ์์ฑํ๋ฉด ๋๋ ๊ฑฑ์ ํ์ง ์์ผ์
๋ ๋ฉ๋๋ค.)
|
| 113 |
-
|
| 114 |
-
Python ํ์ผ chatgpt_app.py ์ ์์ฑํ๊ณ ์๋์ ๊ฐ์ด ์์ฑํฉ๋๋ค. openai.api_key๋ ์์ ์ OpenAI API Key๋ฅผ ์
๋ ฅํฉ๋๋ค. (์: sk-xxxxxxxxxxxxxxxxxxxxx)
|
| 115 |
-
|
| 116 |
-
```python
|
| 117 |
-
import openai
|
| 118 |
-
import streamlit as st
|
| 119 |
-
from streamlit_chat import message
|
| 120 |
-
|
| 121 |
-
openai.api_key = 'YOUR API KEY HERE'
|
| 122 |
-
|
| 123 |
-
def generate_response(prompt):
|
| 124 |
-
completions = openai.Completion.create (
|
| 125 |
-
engine="text-davinci-003",
|
| 126 |
-
prompt=prompt,
|
| 127 |
-
max_tokens=1024,
|
| 128 |
-
stop=None,
|
| 129 |
-
temperature=0,
|
| 130 |
-
top_p=1,
|
| 131 |
-
)
|
| 132 |
-
|
| 133 |
-
message = completions["choices"][0]["text"].replace("\n", "")
|
| 134 |
-
return message
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
st.header("๐คYunwoong's ChatGPT-3 (Demo)")
|
| 138 |
-
st.markdown("[Be Original](https://yunwoong.tistory.com/)")
|
| 139 |
-
|
| 140 |
-
if 'generated' not in st.session_state:
|
| 141 |
-
st.session_state['generated'] = []
|
| 142 |
-
|
| 143 |
-
if 'past' not in st.session_state:
|
| 144 |
-
st.session_state['past'] = []
|
| 145 |
-
|
| 146 |
-
with st.form('form', clear_on_submit=True):
|
| 147 |
-
user_input = st.text_input('You: ', '', key='input')
|
| 148 |
-
submitted = st.form_submit_button('Send')
|
| 149 |
-
|
| 150 |
-
if submitted and user_input:
|
| 151 |
-
output = generate_response(user_input)
|
| 152 |
-
st.session_state.past.append(user_input)
|
| 153 |
-
st.session_state.generated.append(output)
|
| 154 |
-
|
| 155 |
-
if st.session_state['generated']:
|
| 156 |
-
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
| 157 |
-
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
| 158 |
-
message(st.session_state["generated"][i], key=str(i))
|
| 159 |
-
```
|
| 160 |
-
|
| 161 |
-
ํฐ๋ฏธ๋์์ ์๋์ ๊ฐ์ด ์
๋ ฅํ๋ฉด Streamlit ์ฑ์ ์คํํฉ๋๋ค.
|
| 162 |
-
|
| 163 |
-
```bash
|
| 164 |
-
streamlit run chatgpt_app.py
|
| 165 |
-
```
|
| 166 |
-
|
| 167 |
-
<div align="center">
|
| 168 |
-
<img src="https://blog.kakaocdn.net/dn/bceZgF/btr7cdZnqLq/FpszCkE2k72fsQrlS8FSrk/img.gif" width="70%">
|
| 169 |
-
</div>
|
| 170 |
-
|
| 171 |
-
------
|
| 172 |
-
|
| 173 |
-
๋งค์ฐ ๊ฐ๋จํ๊ฒ Web ์ ํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด ์๋ฎฌ๋ ์ด์
์ด ๊ฐ๋ฅํฉ๋๋ค. ๋ง์ผ ๊ฐ๋ฐ์๊ฐ ์๋ ๋ฐ์ดํฐ ๊ณผํ์๋ AI ๋ชจ๋ธ๋ฌ์ธ ๊ฒฝ์ฐ ์๋ฎฌ๋ ์ดํฐ๋ฅผ ๊ตฌ์ถํ๋ ค๋ฉด ์๊ฐ๊ณผ ๋
ธ๋ ฅ์ด ๋ง์ด ๋ค ์ ์์ง๋ง Streamlit์ ์ด์ฉํ๋ค๋ฉด ์ด ๊ณผ์ ์ ๋จ์ํํ๊ณ ์๊ฐ์ ์ ์ฝํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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| 9 |
pinned: false
|
| 10 |
license: openrail
|
| 11 |
---
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: streamlit
|
| 7 |
sdk_version: 1.28.0
|
| 8 |
+
app_file: chatgpt_app.py
|
| 9 |
pinned: false
|
| 10 |
license: openrail
|
| 11 |
---
|