app.py
CHANGED
|
@@ -1,9 +1,47 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
| 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:
|
|
@@ -81,7 +119,17 @@ gradio_app = gr.Interface(
|
|
| 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()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
# Load a text generation pipeline for roleplay scenario generation
|
| 5 |
+
from transformers import pipeline
|
| 6 |
llm_pipeline = pipeline(task="text-generation", model="gpt2") # Replace with your preferred LLM model
|
| 7 |
|
| 8 |
+
# Function to generate random values for the fields
|
| 9 |
+
def generate_random_inputs():
|
| 10 |
+
companion_name = random.choice(["Luna", "Orion", "Zara", "Elio", "Astra"])
|
| 11 |
+
companion_age = random.randint(18, 100)
|
| 12 |
+
companion_gender = random.choice(["Male", "Female", "Non-binary", "Other"])
|
| 13 |
+
companion_species = random.choice(["Human", "Elf", "Cyborg", "Alien", "Dragon"])
|
| 14 |
+
companion_personality = random.choice(["Introverted", "Extroverted", "Calm", "Energetic", "Serious"])
|
| 15 |
+
companion_likes = random.choice(["Books", "Adventure", "Music", "Art", "Technology"])
|
| 16 |
+
companion_dislikes = random.choice(["Loud Noises", "Conflict", "Boredom", "Crowds"])
|
| 17 |
+
companion_hobbies = random.choice(["Painting", "Martial Arts", "Gardening", "Hiking", "Coding"])
|
| 18 |
+
companion_tone = random.choice(["Casual", "Formal", "Sarcastic", "Polite", "Direct"])
|
| 19 |
+
companion_emotional_depth = random.choice(["Shallow", "Deep"])
|
| 20 |
+
companion_abilities = random.choice(["Sword Fighting", "Telepathy", "Invisibility", "Time Travel", "Healing"])
|
| 21 |
+
companion_primary_role = random.choice(["Mentor", "Friend", "Protector", "Guide"])
|
| 22 |
+
companion_secondary_role = random.choice(["Confidant", "Caretaker", "Rival", "Comedian"])
|
| 23 |
+
companion_motivation = random.choice(["Self-Discovery", "Loyalty", "Adventure", "Justice"])
|
| 24 |
+
companion_communication_style = random.choice(["Direct", "Indirect", "Cryptic", "Empathetic"])
|
| 25 |
+
|
| 26 |
+
user_name = random.choice(["Alex", "Jordan", "Taylor", "Morgan", "Casey"])
|
| 27 |
+
user_age = random.randint(18, 60)
|
| 28 |
+
user_relationship_status = random.choice(["Single", "Married", "Complicated", "In a Relationship"])
|
| 29 |
+
|
| 30 |
+
scenario_setting = random.choice(["Futuristic City", "Medieval Village", "Virtual World", "Desert Wasteland"])
|
| 31 |
+
scenario_time_period = random.choice(["Ancient Past", "Modern Day", "Distant Future", "Alternate Reality"])
|
| 32 |
+
scenario_objective = random.choice(["Survival", "Exploration", "Personal Growth", "Solve a Mystery"])
|
| 33 |
+
scenario_events = random.choice(["Natural Disaster", "War", "Festival", "Alien Invasion"])
|
| 34 |
+
scenario_rules = random.choice(["No Violence", "Magic Allowed", "Limited Technology", "No Time Travel"])
|
| 35 |
+
|
| 36 |
+
return [
|
| 37 |
+
companion_name, companion_age, companion_gender, companion_species, companion_personality,
|
| 38 |
+
companion_likes, companion_dislikes, companion_hobbies, companion_tone, companion_emotional_depth,
|
| 39 |
+
companion_abilities, companion_primary_role, companion_secondary_role, companion_motivation, companion_communication_style,
|
| 40 |
+
user_name, user_age, user_relationship_status,
|
| 41 |
+
scenario_setting, scenario_time_period, scenario_objective, scenario_events, scenario_rules
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
# Function to generate a roleplay scenario
|
| 45 |
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):
|
| 46 |
# Combine inputs into a single prompt for the LLM
|
| 47 |
prompt = f"""Generate a roleplay scenario with the following parameters:
|
|
|
|
| 119 |
inputs=companion_fields + user_fields + scenario_fields,
|
| 120 |
outputs=gr.Textbox(label="Generated Roleplay Scenario"),
|
| 121 |
title="Roleplay Scenario Generator",
|
| 122 |
+
live=False
|
| 123 |
)
|
| 124 |
|
| 125 |
+
# Add the "Generate Random Inputs" button
|
| 126 |
+
def populate_random_inputs():
|
| 127 |
+
random_inputs = generate_random_inputs()
|
| 128 |
+
return random_inputs
|
| 129 |
+
|
| 130 |
+
# Create a button to populate the fields with random data
|
| 131 |
+
populate_button = gr.Button("Generate Random Inputs")
|
| 132 |
+
populate_button.click(populate_random_inputs, [], companion_fields + user_fields + scenario_fields)
|
| 133 |
+
|
| 134 |
if __name__ == "__main__":
|
| 135 |
gradio_app.launch()
|