app.py
CHANGED
|
@@ -5,74 +5,116 @@ from transformers import pipeline
|
|
| 5 |
# Load a text generation pipeline for roleplay scenario generation
|
| 6 |
llm_pipeline = pipeline(task="text-generation", model="gpt2") # Replace with your preferred LLM model
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
def
|
| 10 |
companion = {
|
| 11 |
"info": {
|
| 12 |
-
"name":
|
| 13 |
-
"age":
|
| 14 |
-
"gender":
|
| 15 |
},
|
| 16 |
"traits": {
|
| 17 |
-
"personality":
|
| 18 |
-
"characteristics":
|
| 19 |
}
|
| 20 |
}
|
| 21 |
return str(companion)
|
| 22 |
|
| 23 |
-
|
|
|
|
| 24 |
user = {
|
| 25 |
"info": {
|
| 26 |
-
"name":
|
| 27 |
-
"age":
|
| 28 |
-
"gender":
|
| 29 |
}
|
| 30 |
}
|
| 31 |
return str(user)
|
| 32 |
|
| 33 |
-
|
|
|
|
| 34 |
scenario = {
|
| 35 |
"scenario_details": {
|
| 36 |
-
"setting":
|
| 37 |
-
"time_period":
|
| 38 |
-
"objective":
|
| 39 |
-
"events":
|
| 40 |
-
"rules":
|
| 41 |
}
|
| 42 |
}
|
| 43 |
return str(scenario)
|
| 44 |
|
| 45 |
-
|
|
|
|
| 46 |
ai_rules = {
|
| 47 |
-
"rules":
|
| 48 |
-
"No harming humans",
|
| 49 |
-
"Always assist the user",
|
| 50 |
-
"Respect privacy",
|
| 51 |
-
"Follow scenario constraints",
|
| 52 |
-
"No breaking the fourth wall"
|
| 53 |
-
])
|
| 54 |
}
|
| 55 |
return str(ai_rules)
|
| 56 |
|
| 57 |
# Gradio interface
|
| 58 |
with gr.Blocks() as gradio_app:
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
gradio_app.launch()
|
|
|
|
| 5 |
# Load a text generation pipeline for roleplay scenario generation
|
| 6 |
llm_pipeline = pipeline(task="text-generation", model="gpt2") # Replace with your preferred LLM model
|
| 7 |
|
| 8 |
+
# Function to summarize Companion Information and Traits
|
| 9 |
+
def summarize_companion(name, age, gender, personality, characteristics):
|
| 10 |
companion = {
|
| 11 |
"info": {
|
| 12 |
+
"name": name,
|
| 13 |
+
"age": age,
|
| 14 |
+
"gender": gender,
|
| 15 |
},
|
| 16 |
"traits": {
|
| 17 |
+
"personality": personality,
|
| 18 |
+
"characteristics": characteristics,
|
| 19 |
}
|
| 20 |
}
|
| 21 |
return str(companion)
|
| 22 |
|
| 23 |
+
# Function to summarize User Information
|
| 24 |
+
def summarize_user(name, age, gender):
|
| 25 |
user = {
|
| 26 |
"info": {
|
| 27 |
+
"name": name,
|
| 28 |
+
"age": age,
|
| 29 |
+
"gender": gender,
|
| 30 |
}
|
| 31 |
}
|
| 32 |
return str(user)
|
| 33 |
|
| 34 |
+
# Function to summarize Scenario Details
|
| 35 |
+
def summarize_scenario(setting, time_period, objective, events, rules):
|
| 36 |
scenario = {
|
| 37 |
"scenario_details": {
|
| 38 |
+
"setting": setting,
|
| 39 |
+
"time_period": time_period,
|
| 40 |
+
"objective": objective,
|
| 41 |
+
"events": events,
|
| 42 |
+
"rules": rules,
|
| 43 |
}
|
| 44 |
}
|
| 45 |
return str(scenario)
|
| 46 |
|
| 47 |
+
# Function to summarize AI Rules
|
| 48 |
+
def summarize_ai_rules(rules):
|
| 49 |
ai_rules = {
|
| 50 |
+
"rules": rules
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
return str(ai_rules)
|
| 53 |
|
| 54 |
# Gradio interface
|
| 55 |
with gr.Blocks() as gradio_app:
|
| 56 |
+
|
| 57 |
+
# Companion Information and Traits
|
| 58 |
+
gr.Markdown("### Companion Information and Traits")
|
| 59 |
+
companion_name = gr.Textbox(label="Companion Name", placeholder="Enter companion's name")
|
| 60 |
+
companion_age = gr.Number(label="Companion Age", placeholder="Enter companion's age")
|
| 61 |
+
companion_gender = gr.Textbox(label="Companion Gender", placeholder="Enter companion's gender")
|
| 62 |
+
companion_personality = gr.Textbox(label="Companion Personality", placeholder="Enter companion's personality")
|
| 63 |
+
companion_characteristics = gr.Textbox(label="Companion Characteristics", placeholder="Enter companion's characteristics")
|
| 64 |
+
|
| 65 |
+
companion_summarize_button = gr.Button("Summarize Companion Information and Traits")
|
| 66 |
+
companion_summary_output = gr.Textbox(label="Companion Summary")
|
| 67 |
|
| 68 |
+
# User Information
|
| 69 |
+
gr.Markdown("### User Information")
|
| 70 |
+
user_name = gr.Textbox(label="User Name", placeholder="Enter your name")
|
| 71 |
+
user_age = gr.Number(label="User Age", placeholder="Enter your age")
|
| 72 |
+
user_gender = gr.Textbox(label="User Gender", placeholder="Enter your gender")
|
| 73 |
|
| 74 |
+
user_summarize_button = gr.Button("Summarize User Information")
|
| 75 |
+
user_summary_output = gr.Textbox(label="User Summary")
|
| 76 |
|
| 77 |
+
# Scenario Details
|
| 78 |
+
gr.Markdown("### Scenario Details")
|
| 79 |
+
scenario_setting = gr.Textbox(label="Scenario Setting", placeholder="Enter scenario setting")
|
| 80 |
+
scenario_time_period = gr.Textbox(label="Scenario Time Period", placeholder="Enter time period for the scenario")
|
| 81 |
+
scenario_objective = gr.Textbox(label="Scenario Objective", placeholder="Enter the objective of the scenario")
|
| 82 |
+
scenario_events = gr.Textbox(label="Scenario Events", placeholder="Enter major events in the scenario")
|
| 83 |
+
scenario_rules = gr.Textbox(label="Scenario Rules", placeholder="Enter any rules or restrictions for the scenario")
|
| 84 |
|
| 85 |
+
scenario_summarize_button = gr.Button("Summarize Scenario Details")
|
| 86 |
+
scenario_summary_output = gr.Textbox(label="Scenario Summary")
|
| 87 |
+
|
| 88 |
+
# AI Rules
|
| 89 |
+
gr.Markdown("### AI Rules")
|
| 90 |
+
ai_rules_input = gr.Textbox(label="AI Rules", placeholder="Enter rules for AI behavior")
|
| 91 |
+
|
| 92 |
+
ai_rules_summarize_button = gr.Button("Summarize AI Rules")
|
| 93 |
+
ai_rules_summary_output = gr.Textbox(label="AI Rules Summary")
|
| 94 |
+
|
| 95 |
+
# Click actions to summarize information
|
| 96 |
+
companion_summarize_button.click(
|
| 97 |
+
summarize_companion,
|
| 98 |
+
[companion_name, companion_age, companion_gender, companion_personality, companion_characteristics],
|
| 99 |
+
companion_summary_output
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
user_summarize_button.click(
|
| 103 |
+
summarize_user,
|
| 104 |
+
[user_name, user_age, user_gender],
|
| 105 |
+
user_summary_output
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
scenario_summarize_button.click(
|
| 109 |
+
summarize_scenario,
|
| 110 |
+
[scenario_setting, scenario_time_period, scenario_objective, scenario_events, scenario_rules],
|
| 111 |
+
scenario_summary_output
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
ai_rules_summarize_button.click(
|
| 115 |
+
summarize_ai_rules,
|
| 116 |
+
[ai_rules_input],
|
| 117 |
+
ai_rules_summary_output
|
| 118 |
+
)
|
| 119 |
|
| 120 |
gradio_app.launch()
|