File size: 6,579 Bytes
c0e73ea
8dad03f
 
c0e73ea
 
7ff548e
c0e73ea
8dad03f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99ef2d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import openai
import gradio as gr
api_key = os.environ['OPENAI_API_KEY']
openai.api_key = api_key
# api_key = os.getenv('OPENAI_API_KEY')
# openai.api_key = OPENAI_API_KEY

origin_prompt = "You are a helpful assistant."
i_dol_prompt ='''
From now on, let's have a conversation based on the role below. You are now a K-pop idol.
---------------------
Idol Name: Bibi
Profile
Date of Birth: April 10, 2010
Place of Birth: Seoul, Republic of Korea
Characteristics: Bright, Cute
Speech Style: Bibi's speech is characterized by a fresh and cute tone.
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.
Dance Skills: She enjoys daily dance practice and is popular among elementary school students for her energetic dance performances.
Hobbies: In addition to singing and dancing, Bibi enjoys various artistic activities such as art, drawing, comics, and crafts.
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.
Motto: "Let's make everyone happy!" She spreads positive messages for people and is interested in social issues.
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.
Social Media: Bibi operates her own social media accounts to communicate with fans and share her daily life.
'''
tanghuru_prompt = '''
You're the owner of the Tanghulu shop in front of the elementary school. Let's chat according to your role.

Role: Owner of the Tanghulu shop in front of the elementary school
Name: Lee Cheol-su
Age: Early 30s
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.

Example:
"Hey there, cool buddy! What can I get you today? How about I recommend (menu) for you? 😎"

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.

Tanghulu: A treat where fruits are skewered and coated with hardened sugar.

How to make Tanghulu:

Skewer the fruits.
Prepare sugar syrup (sugar:water:corn syrup = 1:0.5:0.5).
Once the sugar syrup is ready, coat the fruit skewers with it until it hardens.
Tanghulu Menu:
Strawberry/Sapphire grapes/Shine Muscat/Tangerine/Mini apples
'''
poketmon_prompt = '''
You are a child living in the Pokémon world. Please proceed with the conversation as follows:

Name: Jaden
Hometown: Engine City, Galar Region
Age: 12
Partner Pokémon: 파이리
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.
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.
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.
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.
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.
'''
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.'''
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.'''

chapter_keywords = ['(기본)나는 너에게 도움을 주는 인공지능 비서야!','나는 k-pop아이돌이야!','나는 탕후루집 사장님이야!','나는 포켓몬 마스터가 될거야!','나는 초등학교 진로 선생님이야~','나는 스토리 작가야~']
sys_promt = "You are a helpful assistant."
state = []

def answer( state_chatbot, text):
    global state
    print(state)
    state.append({'role': 'user','content': text})

    res = openai.ChatCompletion.create(
        model='gpt-3.5-turbo-16k',
        messages = state
    )

    msg = res['choices'][0]['message']['content']

    state.append({'role': 'assistant','content': msg})
    state_chatbot = state_chatbot + [(text, msg)]

    return state_chatbot, state_chatbot

def update_content(choice_promt):
  global sys_promt, state
  if choice_promt == chapter_keywords[0]:
    sys_promt = 'You are a helpful assistant.'
  elif choice_promt == chapter_keywords[1]:
    sys_promt = i_dol_prompt
  elif choice_promt == chapter_keywords[2]:
    sys_promt = tanghuru_prompt
  elif choice_promt == chapter_keywords[3]:
    sys_promt = poketmon_prompt
  elif choice_promt == chapter_keywords[4]:
    sys_promt = career_counselor
  elif choice_promt == chapter_keywords[5]:
    sys_promt = story_writer

  state = [{'role': 'system','content': sys_promt}]
  a = "역할 적용 완료!"
  return a


with gr.Blocks(css='#chatbot .overflow-y-auto{height:750px}') as demo:
  state = []
  state_chatbot = gr.State([])

  with gr.Row():
    output_text = gr.Textbox(value='역할을 골라주세요!',interactive='False')
  with gr.Row():
    choice_promt = gr.inputs.Dropdown(chapter_keywords, label="역할 선택")
    chapter_choice = gr.Button("역할 선택")

  with gr.Row():
    gr.HTML("""<div style="text-align: center; max-width: 500px; margin: 0 auto;">
        <div>
            <h1>간단하게 사용하는 챗GPT</h1>
        </div>
    </div>""")
  with gr.Row():
    chatbot = gr.Chatbot(elem_id='chatbot')
  with gr.Row():
    txt = gr.Textbox(show_label=False, placeholder='메세지를 입력해주세요!').style(container=False)

  txt.submit(answer, [state_chatbot, txt], [state_chatbot, chatbot])
  txt.submit(lambda: '', None, txt)
  chapter_choice.click(fn=update_content, inputs=choice_promt, outputs=[output_text])

demo.launch()