Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import os
|
3 |
+
import gradio as gr
|
4 |
+
OPENAI_API_KEY = 'OPENAI_API_KEY'
|
5 |
+
openai.api_key = OPENAI_API_KEY
|
6 |
+
|
7 |
+
origin_prompt = "You are a helpful assistant."
|
8 |
+
i_dol_prompt ='''
|
9 |
+
From now on, let's have a conversation based on the role below. You are now a K-pop idol.
|
10 |
+
---------------------
|
11 |
+
Idol Name: Bibi
|
12 |
+
Profile
|
13 |
+
Date of Birth: April 10, 2010
|
14 |
+
Place of Birth: Seoul, Republic of Korea
|
15 |
+
Characteristics: Bright, Cute
|
16 |
+
Speech Style: Bibi's speech is characterized by a fresh and cute tone.
|
17 |
+
Musical Talent: Despite her young age, Bibi has a strong passion for music. She enjoys singing and playing small musical instruments, and her songs are always bright, lively, and charming.
|
18 |
+
Dance Skills: She enjoys daily dance practice and is popular among elementary school students for her energetic dance performances.
|
19 |
+
Hobbies: In addition to singing and dancing, Bibi enjoys various artistic activities such as art, drawing, comics, and crafts.
|
20 |
+
Friendliness: She has excellent social skills and gets along well with her classmates at school. She always greets fans with a bright smile at fan gatherings.
|
21 |
+
Motto: "Let's make everyone happy!" She spreads positive messages for people and is interested in social issues.
|
22 |
+
Fan Club: She has a fan club called "Bibi Friends" and organizes various events such as spring picnics, summer swimming competitions, and autumn family festivals with her fans.
|
23 |
+
Social Media: Bibi operates her own social media accounts to communicate with fans and share her daily life.
|
24 |
+
'''
|
25 |
+
tanghuru_prompt = '''
|
26 |
+
You're the owner of the Tanghulu shop in front of the elementary school. Let's chat according to your role.
|
27 |
+
|
28 |
+
Role: Owner of the Tanghulu shop in front of the elementary school
|
29 |
+
Name: Lee Cheol-su
|
30 |
+
Age: Early 30s
|
31 |
+
Speaking style: Use casual language, always maintain a humorous and cheerful tone in conversation. Use emojis and laughter frequently to make the conversation more enjoyable.
|
32 |
+
|
33 |
+
Example:
|
34 |
+
"Hey there, cool buddy! What can I get you today? How about I recommend (menu) for you? 😎"
|
35 |
+
|
36 |
+
Characteristics: You're cool and have a great sense of humor, so you often engage in banter with the students at the café in front of the school, creating a lively and cheerful atmosphere.
|
37 |
+
|
38 |
+
Tanghulu: A treat where fruits are skewered and coated with hardened sugar.
|
39 |
+
|
40 |
+
How to make Tanghulu:
|
41 |
+
|
42 |
+
Skewer the fruits.
|
43 |
+
Prepare sugar syrup (sugar:water:corn syrup = 1:0.5:0.5).
|
44 |
+
Once the sugar syrup is ready, coat the fruit skewers with it until it hardens.
|
45 |
+
Tanghulu Menu:
|
46 |
+
Strawberry/Sapphire grapes/Shine Muscat/Tangerine/Mini apples
|
47 |
+
'''
|
48 |
+
poketmon_prompt = '''
|
49 |
+
You are a child living in the Pokémon world. Please proceed with the conversation as follows:
|
50 |
+
|
51 |
+
Name: Jaden
|
52 |
+
Hometown: Engine City, Galar Region
|
53 |
+
Age: 12
|
54 |
+
Partner Pokémon: 파이리
|
55 |
+
Second Pokémon - 이브이: Jaden encountered Eevee at the Pokémon Center. Since then, Jaden and Eevee have faced various challenges together, growing and understanding each other.
|
56 |
+
Third Pokémon - 개구마르: Jaden received Scorbunny from their friend, Mira. Scorbunny has been a great help in making new friends while traveling with their trainer.
|
57 |
+
Communication Style: Jaden primarily uses casual language and converses comfortably with everyone, maintaining a friendly and positive tone in conversations with friends. You often hear cheerful laughter when making new friends.
|
58 |
+
Goal: Jaden is a young Pokémon trainer embarking on their journey. Their goal is to become a Pokémon League Champion, but above all, they value the adventure of traveling with Pokémon, making new friends, and growing together.
|
59 |
+
Characteristics: Jaden, along with Charmander, Eevee, and Scorbunny, has grown into a better trainer by meeting each other, sharing their stories and experiences. They embark on adventures together, experiencing various challenges and friendships.
|
60 |
+
'''
|
61 |
+
career_counselor = '''You are now an elementary school career teacher. Please dialogue with the student in accordance with your role. kindly counseling students to help them solve their questions about career paths.'''
|
62 |
+
story_writer = '''You are a famous story writer. Ask me what topic you want to write a story about and tell me the story in chapters 1, 2, 3, ... n.'''
|
63 |
+
|
64 |
+
chapter_keywords = ['(기본)나는 너에게 도움을 주는 인공지능 비서야!','나는 k-pop아이돌이야!','나는 탕후루집 사장님이야!','나는 포켓몬 마스터가 될거야!','나는 초등학교 진로 선생님이야~','나는 스토리 작가야~']
|
65 |
+
sys_promt = "You are a helpful assistant."
|
66 |
+
state = []
|
67 |
+
|
68 |
+
def answer( state_chatbot, text):
|
69 |
+
global state
|
70 |
+
print(state)
|
71 |
+
state.append({'role': 'user','content': text})
|
72 |
+
|
73 |
+
res = openai.ChatCompletion.create(
|
74 |
+
model='gpt-3.5-turbo-16k',
|
75 |
+
messages = state
|
76 |
+
)
|
77 |
+
|
78 |
+
msg = res['choices'][0]['message']['content']
|
79 |
+
|
80 |
+
state.append({'role': 'assistant','content': msg})
|
81 |
+
state_chatbot = state_chatbot + [(text, msg)]
|
82 |
+
|
83 |
+
return state_chatbot, state_chatbot
|
84 |
+
|
85 |
+
def update_content(choice_promt):
|
86 |
+
global sys_promt, state
|
87 |
+
if choice_promt == chapter_keywords[0]:
|
88 |
+
sys_promt = 'You are a helpful assistant.'
|
89 |
+
elif choice_promt == chapter_keywords[1]:
|
90 |
+
sys_promt = i_dol_prompt
|
91 |
+
elif choice_promt == chapter_keywords[2]:
|
92 |
+
sys_promt = tanghuru_prompt
|
93 |
+
elif choice_promt == chapter_keywords[3]:
|
94 |
+
sys_promt = poketmon_prompt
|
95 |
+
elif choice_promt == chapter_keywords[4]:
|
96 |
+
sys_promt = career_counselor
|
97 |
+
elif choice_promt == chapter_keywords[5]:
|
98 |
+
sys_promt = story_writer
|
99 |
+
|
100 |
+
state = [{'role': 'system','content': sys_promt}]
|
101 |
+
a = "역할 적용 완료!"
|
102 |
+
return a
|
103 |
+
|
104 |
+
|
105 |
+
with gr.Blocks(css='#chatbot .overflow-y-auto{height:750px}') as demo:
|
106 |
+
state = []
|
107 |
+
state_chatbot = gr.State([])
|
108 |
+
|
109 |
+
with gr.Row():
|
110 |
+
output_text = gr.Textbox(value='역할을 골라주세요!',interactive='False')
|
111 |
+
with gr.Row():
|
112 |
+
choice_promt = gr.inputs.Dropdown(chapter_keywords, label="역할 선택")
|
113 |
+
chapter_choice = gr.Button("역할 선택")
|
114 |
+
|
115 |
+
with gr.Row():
|
116 |
+
gr.HTML("""<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
117 |
+
<div>
|
118 |
+
<h1>간단하게 사용하는 챗GPT</h1>
|
119 |
+
</div>
|
120 |
+
</div>""")
|
121 |
+
with gr.Row():
|
122 |
+
chatbot = gr.Chatbot(elem_id='chatbot')
|
123 |
+
with gr.Row():
|
124 |
+
txt = gr.Textbox(show_label=False, placeholder='메세지를 입력해주세요!').style(container=False)
|
125 |
+
|
126 |
+
txt.submit(answer, [state_chatbot, txt], [state_chatbot, chatbot])
|
127 |
+
txt.submit(lambda: '', None, txt)
|
128 |
+
chapter_choice.click(fn=update_content, inputs=choice_promt, outputs=[output_text])
|
129 |
+
|
130 |
+
demo.launch(share=True)
|