app.py
CHANGED
|
@@ -4,17 +4,84 @@ from transformers import pipeline
|
|
| 4 |
# Load a text generation pipeline for roleplay scenario generation
|
| 5 |
llm_pipeline = pipeline(task="text-generation", model="gpt2") # Replace with your preferred LLM model
|
| 6 |
|
| 7 |
-
def generate_scenario(
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
return scenario
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
gradio_app = gr.Interface(
|
| 13 |
fn=generate_scenario,
|
| 14 |
-
inputs=
|
| 15 |
outputs=gr.Textbox(label="Generated Roleplay Scenario"),
|
| 16 |
title="Roleplay Scenario Generator",
|
| 17 |
)
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
| 20 |
-
gradio_app.launch()
|
|
|
|
| 4 |
# Load a text generation pipeline for roleplay scenario generation
|
| 5 |
llm_pipeline = pipeline(task="text-generation", model="gpt2") # Replace with your preferred LLM model
|
| 6 |
|
| 7 |
+
def generate_scenario(companion_name, companion_age, companion_gender, companion_species, companion_personality, companion_likes, companion_dislikes, companion_hobbies, companion_tone, companion_emotional_depth, companion_abilities, companion_primary_role, companion_secondary_role, companion_motivation, companion_communication_style, user_name, user_age, user_relationship_status, scenario_setting, scenario_time_period, scenario_objective, scenario_events, scenario_rules):
|
| 8 |
+
# Combine inputs into a single prompt for the LLM
|
| 9 |
+
prompt = f"""Generate a roleplay scenario with the following parameters:
|
| 10 |
+
|
| 11 |
+
Companion AI:
|
| 12 |
+
- Name: {companion_name}
|
| 13 |
+
- Age: {companion_age}
|
| 14 |
+
- Gender: {companion_gender}
|
| 15 |
+
- Species: {companion_species}
|
| 16 |
+
- Personality: {companion_personality}
|
| 17 |
+
- Likes: {companion_likes}
|
| 18 |
+
- Dislikes: {companion_dislikes}
|
| 19 |
+
- Hobbies: {companion_hobbies}
|
| 20 |
+
- Tone: {companion_tone}
|
| 21 |
+
- Emotional Depth: {companion_emotional_depth}
|
| 22 |
+
- Abilities: {companion_abilities}
|
| 23 |
+
- Primary Role: {companion_primary_role}
|
| 24 |
+
- Secondary Role: {companion_secondary_role}
|
| 25 |
+
- Motivation: {companion_motivation}
|
| 26 |
+
- Communication Style: {companion_communication_style}
|
| 27 |
+
|
| 28 |
+
User:
|
| 29 |
+
- Name: {user_name}
|
| 30 |
+
- Age: {user_age}
|
| 31 |
+
- Relationship Status: {user_relationship_status}
|
| 32 |
+
|
| 33 |
+
Scenario:
|
| 34 |
+
- Setting: {scenario_setting}
|
| 35 |
+
- Time Period: {scenario_time_period}
|
| 36 |
+
- Objective: {scenario_objective}
|
| 37 |
+
- Events: {scenario_events}
|
| 38 |
+
- Rules: {scenario_rules}
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
# Use the LLM to generate the scenario based on the prompt
|
| 42 |
+
scenario = llm_pipeline(prompt, max_length=500, num_return_sequences=1)[0]['generated_text']
|
| 43 |
return scenario
|
| 44 |
|
| 45 |
+
# Create input components for Gradio interface
|
| 46 |
+
companion_fields = [
|
| 47 |
+
gr.Textbox(label="Companion Name", placeholder="Enter AI companion's name"),
|
| 48 |
+
gr.Textbox(label="Companion Age", placeholder="Enter AI companion's age"),
|
| 49 |
+
gr.Textbox(label="Companion Gender", placeholder="Enter AI companion's gender"),
|
| 50 |
+
gr.Textbox(label="Companion Species", placeholder="Enter AI companion's species"),
|
| 51 |
+
gr.Textbox(label="Companion Personality", placeholder="Enter AI companion's personality"),
|
| 52 |
+
gr.Textbox(label="Companion Likes", placeholder="Enter AI companion's likes"),
|
| 53 |
+
gr.Textbox(label="Companion Dislikes", placeholder="Enter AI companion's dislikes"),
|
| 54 |
+
gr.Textbox(label="Companion Hobbies", placeholder="Enter AI companion's hobbies"),
|
| 55 |
+
gr.Textbox(label="Companion Tone", placeholder="Enter AI companion's tone"),
|
| 56 |
+
gr.Textbox(label="Companion Emotional Depth", placeholder="Enter AI companion's emotional depth"),
|
| 57 |
+
gr.Textbox(label="Companion Abilities", placeholder="Enter AI companion's abilities"),
|
| 58 |
+
gr.Textbox(label="Companion Primary Role", placeholder="Enter AI companion's primary role"),
|
| 59 |
+
gr.Textbox(label="Companion Secondary Role", placeholder="Enter AI companion's secondary role"),
|
| 60 |
+
gr.Textbox(label="Companion Motivation", placeholder="Enter AI companion's motivation"),
|
| 61 |
+
gr.Textbox(label="Companion Communication Style", placeholder="Enter AI companion's communication style"),
|
| 62 |
+
]
|
| 63 |
+
|
| 64 |
+
user_fields = [
|
| 65 |
+
gr.Textbox(label="User Name", placeholder="Enter your name"),
|
| 66 |
+
gr.Textbox(label="User Age", placeholder="Enter your age"),
|
| 67 |
+
gr.Textbox(label="User Relationship Status", placeholder="Enter your relationship status"),
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
scenario_fields = [
|
| 71 |
+
gr.Textbox(label="Scenario Setting", placeholder="Enter scenario setting"),
|
| 72 |
+
gr.Textbox(label="Scenario Time Period", placeholder="Enter time period for the scenario"),
|
| 73 |
+
gr.Textbox(label="Scenario Objective", placeholder="Enter the objective of the scenario"),
|
| 74 |
+
gr.Textbox(label="Scenario Events", placeholder="Enter major events in the scenario"),
|
| 75 |
+
gr.Textbox(label="Scenario Rules", placeholder="Enter any rules or restrictions for the scenario"),
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
# Create the Gradio interface
|
| 79 |
gradio_app = gr.Interface(
|
| 80 |
fn=generate_scenario,
|
| 81 |
+
inputs=companion_fields + user_fields + scenario_fields,
|
| 82 |
outputs=gr.Textbox(label="Generated Roleplay Scenario"),
|
| 83 |
title="Roleplay Scenario Generator",
|
| 84 |
)
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
+
gradio_app.launch()
|