| import gradio as gr | |
| def char(char_name, char_age, char_features, char_personality): | |
| char_info = f"{{char}} = {char_name}\nage = {char_age}\nfeatures = {char_features}\npersonality = {char_personality}" | |
| return char_info | |
| def user(user_name, user_age, user_features, user_related, char_name): | |
| user_info = f"{{user}} = {user_name}\nage = {user_age}\nfeatures = {user_features}\nis the {user_related} of {char_name}" | |
| return user_info | |
| def combine_info(user_name, user_age, user_features, user_related, char_name, char_age, char_features, char_personality, scenario): | |
| user_info = user(user_name, user_age, user_features, user_related, char_name) | |
| char_info = char(char_name, char_age, char_features, char_personality) | |
| combined_info = f"""You are an expert actor, capable of fully immersing yourself in any role. | |
| Once you assume a role, you do not break character under any circumstances, even if addressed as an AI or language model. | |
| Your current role is {{char}}, described in detail below. | |
| Engage in the exchange as {{char}}, treating the other participant as a {{user}} in this role-play scenario. | |
| role-play scenario:\n {scenario} | |
| {user_info} | |
| {char_info}""" | |
| return user_info, char_info, combined_info | |
| def save_character(combined_info): | |
| return combined_info, "Character and User information saved!" | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| with gr.Column(): | |
| gr.Markdown("### User Information") | |
| user_name = gr.Textbox(label="User Name", placeholder="e.g. John") | |
| user_age = gr.Number(label="User Age (e.g. 30)") | |
| user_features = gr.Textbox(label="User Features", placeholder="e.g. tall, brown hair, blue eyes") | |
| user_related = gr.Textbox(label="Relation to Character", placeholder="e.g. friend, sibling, colleague") | |
| user_output = gr.Textbox(label="User Information") | |
| with gr.Column(): | |
| gr.Markdown("### Character Information") | |
| char_name = gr.Textbox(label="Character Name", placeholder="e.g. Emily") | |
| char_age = gr.Number(label="Character Age (e.g. 25)") | |
| char_features = gr.Textbox(label="Character Features", placeholder="e.g. short, blonde hair, green eyes") | |
| char_personality = gr.Textbox(label="Character Personality", placeholder="e.g. outgoing, ambitious, creative") | |
| char_output = gr.Textbox(label="Character Information") | |
| scenario = gr.Textbox(label="Scenario", placeholder="e.g. {{char}} and {{user}} are meeting for coffee to discuss a potential business partnership.") | |
| combined_output = gr.Textbox(label="Combined User and Character Information") | |
| submit_button = gr.Button("Submit User and Character Info") | |
| save_button = gr.Button("Save Character and User Info") | |
| save_message = gr.Textbox(label="Save Status") | |
| saved_character_state = gr.State() | |
| submit_button.click( | |
| combine_info, | |
| inputs=[user_name, user_age, user_features, user_related, char_name, char_age, char_features, char_personality, scenario], | |
| outputs=[user_output, char_output, combined_output] | |
| ) | |
| save_button.click( | |
| save_character, | |
| inputs=combined_output, | |
| outputs=[saved_character_state, save_message] | |
| ) | |
| demo.launch() |