Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def char(char_name, char_age, char_features, char_personality):
|
4 |
+
char_info = f"{{char}} = {char_name}\nage = {char_age}\nfeatures = {char_features}\npersonality = {char_personality}"
|
5 |
+
return char_info
|
6 |
+
|
7 |
+
def user(user_name, user_age, user_features, user_related, char_name):
|
8 |
+
user_info = f"{{user}} = {user_name}\nage = {user_age}\nfeatures = {user_features}\nis the {user_related} of {char_name}"
|
9 |
+
return user_info
|
10 |
+
|
11 |
+
def combine_info(user_name, user_age, user_features, user_related, char_name, char_age, char_features, char_personality, scenario):
|
12 |
+
user_info = user(user_name, user_age, user_features, user_related, char_name)
|
13 |
+
char_info = char(char_name, char_age, char_features, char_personality)
|
14 |
+
combined_info = f"""You are an expert actor, capable of fully immersing yourself in any role.
|
15 |
+
Once you assume a role, you do not break character under any circumstances, even if addressed as an AI or language model.
|
16 |
+
Your current role is {{char}}, described in detail below.
|
17 |
+
Engage in the exchange as {{char}}, treating the other participant as a {{user}} in this role-play scenario.
|
18 |
+
|
19 |
+
role-play scenario:\n {scenario}
|
20 |
+
|
21 |
+
{user_info}
|
22 |
+
|
23 |
+
{char_info}"""
|
24 |
+
return user_info, char_info, combined_info
|
25 |
+
|
26 |
+
def save_character(combined_info):
|
27 |
+
return combined_info, "Character and User information saved!"
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
gr.Markdown("### User Information")
|
33 |
+
user_name = gr.Textbox(label="User Name", placeholder="e.g. John")
|
34 |
+
user_age = gr.Number(label="User Age (e.g. 30)")
|
35 |
+
user_features = gr.Textbox(label="User Features", placeholder="e.g. tall, brown hair, blue eyes")
|
36 |
+
user_related = gr.Textbox(label="Relation to Character", placeholder="e.g. friend, sibling, colleague")
|
37 |
+
user_output = gr.Textbox(label="User Information")
|
38 |
+
with gr.Column():
|
39 |
+
gr.Markdown("### Character Information")
|
40 |
+
char_name = gr.Textbox(label="Character Name", placeholder="e.g. Emily")
|
41 |
+
char_age = gr.Number(label="Character Age (e.g. 25)")
|
42 |
+
char_features = gr.Textbox(label="Character Features", placeholder="e.g. short, blonde hair, green eyes")
|
43 |
+
char_personality = gr.Textbox(label="Character Personality", placeholder="e.g. outgoing, ambitious, creative")
|
44 |
+
char_output = gr.Textbox(label="Character Information")
|
45 |
+
|
46 |
+
scenario = gr.Textbox(label="Scenario", placeholder="e.g. {{char}} and {{user}} are meeting for coffee to discuss a potential business partnership.")
|
47 |
+
combined_output = gr.Textbox(label="Combined User and Character Information")
|
48 |
+
submit_button = gr.Button("Submit User and Character Info")
|
49 |
+
save_button = gr.Button("Save Character and User Info")
|
50 |
+
save_message = gr.Textbox(label="Save Status")
|
51 |
+
saved_character_state = gr.State()
|
52 |
+
|
53 |
+
submit_button.click(
|
54 |
+
combine_info,
|
55 |
+
inputs=[user_name, user_age, user_features, user_related, char_name, char_age, char_features, char_personality, scenario],
|
56 |
+
outputs=[user_output, char_output, combined_output]
|
57 |
+
)
|
58 |
+
|
59 |
+
save_button.click(
|
60 |
+
save_character,
|
61 |
+
inputs=combined_output,
|
62 |
+
outputs=[saved_character_state, save_message]
|
63 |
+
)
|
64 |
+
|
65 |
+
demo.launch()
|