Ridealist commited on
Commit
623e590
โ€ข
1 Parent(s): 2872c06

Delete unused files

Browse files
Files changed (2) hide show
  1. README copy.md +0 -173
  2. 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
- ![img](https://blog.kakaocdn.net/dn/xKSqg/btr62GPoKvC/OF7uLj6YZhmv1VkVyDOJN0/img.png)
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์„ ์ด์šฉํ•œ๋‹ค๋ฉด ์ด ๊ณผ์ •์„ ๋‹จ์ˆœํ™”ํ•˜๊ณ  ์‹œ๊ฐ„์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -5,7 +5,7 @@ colorFrom: yellow
5
  colorTo: green
6
  sdk: streamlit
7
  sdk_version: 1.28.0
8
- app_file: app.py
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
  ---