Update app.py
Browse files
app.py
CHANGED
|
@@ -32,29 +32,13 @@ st.markdown('###### openAI key를 입력하고, 코드가 필요한 상황, 작
|
|
| 32 |
api_key = st.text_input(label='openAI의 api key를 입력하세요.', placeholder='sk-...', type='password')
|
| 33 |
|
| 34 |
|
| 35 |
-
def generate_recommend(prompt):
|
| 36 |
-
completions = client.completions.create (
|
| 37 |
-
model="gpt-3.5-turbo-instruct",
|
| 38 |
-
#engine="text-davinci-003",
|
| 39 |
-
prompt=prompt,
|
| 40 |
-
temperature=0,
|
| 41 |
-
max_tokens=400,
|
| 42 |
-
top_p=1,
|
| 43 |
-
frequency_penalty=0,
|
| 44 |
-
presence_penalty=0
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
message = completions.choices[0].text.replace(",", " ] [ ")
|
| 48 |
-
return message
|
| 49 |
-
|
| 50 |
-
# load_dotenv()
|
| 51 |
|
| 52 |
if api_key:
|
| 53 |
openai.api_key = api_key
|
| 54 |
client = openai.Client()
|
| 55 |
else:
|
| 56 |
st.warning("유효한 API 키를 입력해 주세요.")
|
| 57 |
-
|
| 58 |
|
| 59 |
if api_key:
|
| 60 |
# 텍스트 입력
|
|
@@ -102,6 +86,21 @@ if api_key:
|
|
| 102 |
# 버튼 클릭
|
| 103 |
button = st.button(':gift:코드블럭 추천받기')
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
if button:
|
| 106 |
output = generate_recommend(prompt)
|
| 107 |
st.write(f'{output}')
|
|
|
|
| 32 |
api_key = st.text_input(label='openAI의 api key를 입력하세요.', placeholder='sk-...', type='password')
|
| 33 |
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if api_key:
|
| 37 |
openai.api_key = api_key
|
| 38 |
client = openai.Client()
|
| 39 |
else:
|
| 40 |
st.warning("유효한 API 키를 입력해 주세요.")
|
| 41 |
+
client = None # client 변수를 None으로 초기화
|
| 42 |
|
| 43 |
if api_key:
|
| 44 |
# 텍스트 입력
|
|
|
|
| 86 |
# 버튼 클릭
|
| 87 |
button = st.button(':gift:코드블럭 추천받기')
|
| 88 |
|
| 89 |
+
|
| 90 |
+
if client: # client가 None이 아닌 경우에만 실행
|
| 91 |
+
def generate_recommend(prompt):
|
| 92 |
+
completions = client.completions.create(
|
| 93 |
+
model="gpt-3.5-turbo-instruct",
|
| 94 |
+
prompt=prompt,
|
| 95 |
+
temperature=0,
|
| 96 |
+
max_tokens=400,
|
| 97 |
+
top_p=1,
|
| 98 |
+
frequency_penalty=0,
|
| 99 |
+
presence_penalty=0
|
| 100 |
+
)
|
| 101 |
+
message = completions.choices[0].text.replace(",", " ] [ ")
|
| 102 |
+
return message
|
| 103 |
+
|
| 104 |
if button:
|
| 105 |
output = generate_recommend(prompt)
|
| 106 |
st.write(f'{output}')
|