xtreme86 commited on
Commit
f5485cb
·
1 Parent(s): 59887a9
Files changed (1) hide show
  1. app.py +81 -39
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
- # Functions to generate random values for each section
9
- def generate_companion_info_traits():
10
  companion = {
11
  "info": {
12
- "name": random.choice(["Luna", "Orion", "Zara", "Elio", "Astra"]),
13
- "age": random.randint(18, 100),
14
- "gender": random.choice(["Male", "Female", "Non-binary", "Other"]),
15
  },
16
  "traits": {
17
- "personality": random.choice(["Introverted", "Extroverted", "Calm", "Energetic", "Serious"]),
18
- "characteristics": random.choice(["Brave", "Cunning", "Kind", "Loyal", "Mysterious"]),
19
  }
20
  }
21
  return str(companion)
22
 
23
- def generate_user_info():
 
24
  user = {
25
  "info": {
26
- "name": random.choice(["Alex", "Jordan", "Taylor", "Morgan", "Casey"]),
27
- "age": random.randint(18, 60),
28
- "gender": random.choice(["Male", "Female", "Non-binary", "Other"]),
29
  }
30
  }
31
  return str(user)
32
 
33
- def generate_scenario_details():
 
34
  scenario = {
35
  "scenario_details": {
36
- "setting": random.choice(["Futuristic City", "Medieval Village", "Virtual World", "Desert Wasteland"]),
37
- "time_period": random.choice(["Ancient Past", "Modern Day", "Distant Future", "Alternate Reality"]),
38
- "objective": random.choice(["Survival", "Exploration", "Personal Growth", "Solve a Mystery"]),
39
- "events": random.choice(["Natural Disaster", "War", "Festival", "Alien Invasion"]),
40
- "rules": random.choice(["No Violence", "Magic Allowed", "Limited Technology", "No Time Travel"]),
41
  }
42
  }
43
  return str(scenario)
44
 
45
- def generate_ai_rules():
 
46
  ai_rules = {
47
- "rules": random.choice([
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
- # Buttons and corresponding outputs for each generation function
60
- generate_companion_button = gr.Button("Generate Companion Information and Traits")
61
- companion_output = gr.Textbox(label="Companion Information and Traits")
 
 
 
 
 
 
 
 
62
 
63
- generate_user_button = gr.Button("Generate User Information")
64
- user_output = gr.Textbox(label="User Information")
 
 
 
65
 
66
- generate_scenario_button = gr.Button("Generate Scenario between User and Companion")
67
- scenario_output = gr.Textbox(label="Scenario Details")
68
 
69
- generate_ai_rules_button = gr.Button("Generate AI Rules")
70
- ai_rules_output = gr.Textbox(label="AI Rules")
 
 
 
 
 
71
 
72
- # Linking buttons to their respective functions
73
- generate_companion_button.click(generate_companion_info_traits, [], companion_output)
74
- generate_user_button.click(generate_user_info, [], user_output)
75
- generate_scenario_button.click(generate_scenario_details, [], scenario_output)
76
- generate_ai_rules_button.click(generate_ai_rules, [], ai_rules_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()