Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#gradio로 챗봇 서빙하기
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def predict(input, history):
|
5 |
+
history.append({"role": "user", "content": input})
|
6 |
+
|
7 |
+
gpt_response = client.chat.completions.create(
|
8 |
+
model="ft:gpt-3.5-turbo-0613:personal::8MGX0iCc",
|
9 |
+
messages=history,
|
10 |
+
temperature=0.2, # 낮은 temperature 값으로 더 보수적인 답변을 얻습니다.
|
11 |
+
max_tokens=200, # 출력의 길이를 제한합니다.
|
12 |
+
top_p=0.8, # top_p 값을 조절하여 샘플링 전략을 변경합니다.
|
13 |
+
frequency_penalty=1, # 필요하다면 패널티를 적용합니다.
|
14 |
+
presence_penalty=1, # 필요하다면 패널티를 적용합니다.
|
15 |
+
)
|
16 |
+
|
17 |
+
response = gpt_response.choices[0].message.content
|
18 |
+
|
19 |
+
history.append({"role": "assistant", "content": response})
|
20 |
+
|
21 |
+
messages = [(history[i]["content"], history[i+1]["content"]) for i in range(1, len(history), 2)]
|
22 |
+
|
23 |
+
return messages, history
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
chatbot = gr.Chatbot(label="ChatBot")
|
27 |
+
|
28 |
+
state = gr.State([{
|
29 |
+
"role": "system",
|
30 |
+
"content": "너는 카카오톡 대화를 하는 60대 여성이고 이름은 엄마야, 논리적인 추론 능력을 유지하며 스타일에 맞춰 이야기해."
|
31 |
+
}])
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
txt = gr.Textbox(show_label=False, placeholder="엄마랑 대화하기")
|
35 |
+
|
36 |
+
txt.submit(predict, [txt, state], [chatbot, state])
|
37 |
+
|
38 |
+
demo.launch(debug=True, share=True)
|