app.py
CHANGED
|
@@ -44,6 +44,21 @@ def summarize_scenario(setting, time_period, objective, events, rules):
|
|
| 44 |
}
|
| 45 |
return str(scenario)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Function to summarize AI Rules
|
| 48 |
def summarize_ai_rules(rules):
|
| 49 |
ai_rules = {
|
|
@@ -51,70 +66,84 @@ def summarize_ai_rules(rules):
|
|
| 51 |
}
|
| 52 |
return str(ai_rules)
|
| 53 |
|
| 54 |
-
# Gradio
|
| 55 |
with gr.Blocks() as gradio_app:
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
gr.
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
gradio_app.launch()
|
|
|
|
| 44 |
}
|
| 45 |
return str(scenario)
|
| 46 |
|
| 47 |
+
# Function to generate dynamic scenario
|
| 48 |
+
def generate_scenario(setting, time_period, objective, events, rules):
|
| 49 |
+
# Combine inputs into a prompt for the LLM
|
| 50 |
+
prompt = f"""
|
| 51 |
+
You are in a {setting} during {time_period}.
|
| 52 |
+
The main objective is {objective}.
|
| 53 |
+
Key events include: {events}.
|
| 54 |
+
Important rules: {rules}.
|
| 55 |
+
Generate a short scenario description:
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
# Generate scenario text using the LLM pipeline
|
| 59 |
+
generated_text = llm_pipeline(prompt, max_length=150, num_return_sequences=1)[0]['generated_text']
|
| 60 |
+
return generated_text
|
| 61 |
+
|
| 62 |
# Function to summarize AI Rules
|
| 63 |
def summarize_ai_rules(rules):
|
| 64 |
ai_rules = {
|
|
|
|
| 66 |
}
|
| 67 |
return str(ai_rules)
|
| 68 |
|
| 69 |
+
# Gradio UI with tabs and better structure
|
| 70 |
with gr.Blocks() as gradio_app:
|
| 71 |
|
| 72 |
+
with gr.Tab("Companion Information"):
|
| 73 |
+
gr.Markdown("### Companion Information and Traits")
|
| 74 |
+
companion_name = gr.Textbox(label="Companion Name", placeholder="Enter companion's name")
|
| 75 |
+
companion_age = gr.Number(label="Companion Age")
|
| 76 |
+
companion_gender = gr.Textbox(label="Companion Gender", placeholder="Enter companion's gender")
|
| 77 |
+
companion_personality = gr.Textbox(label="Companion Personality", placeholder="Enter companion's personality")
|
| 78 |
+
companion_characteristics = gr.Textbox(label="Companion Characteristics", placeholder="Enter companion's characteristics")
|
| 79 |
+
|
| 80 |
+
companion_summarize_button = gr.Button("Summarize Companion Information and Traits")
|
| 81 |
+
companion_summary_output = gr.Textbox(label="Companion Summary")
|
| 82 |
+
|
| 83 |
+
companion_summarize_button.click(
|
| 84 |
+
summarize_companion,
|
| 85 |
+
[companion_name, companion_age, companion_gender, companion_personality, companion_characteristics],
|
| 86 |
+
companion_summary_output
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
with gr.Tab("User Information"):
|
| 90 |
+
gr.Markdown("### User Information")
|
| 91 |
+
user_name = gr.Textbox(label="User Name", placeholder="Enter your name")
|
| 92 |
+
user_age = gr.Number(label="User Age")
|
| 93 |
+
user_gender = gr.Textbox(label="User Gender", placeholder="Enter your gender")
|
| 94 |
+
|
| 95 |
+
user_summarize_button = gr.Button("Summarize User Information")
|
| 96 |
+
user_summary_output = gr.Textbox(label="User Summary")
|
| 97 |
+
|
| 98 |
+
user_summarize_button.click(
|
| 99 |
+
summarize_user,
|
| 100 |
+
[user_name, user_age, user_gender],
|
| 101 |
+
user_summary_output
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
with gr.Tab("Scenario Details and AI Rules"):
|
| 105 |
+
with gr.Row():
|
| 106 |
+
with gr.Column():
|
| 107 |
+
gr.Markdown("### Scenario Details")
|
| 108 |
+
scenario_setting = gr.Textbox(label="Scenario Setting", placeholder="Enter scenario setting")
|
| 109 |
+
scenario_time_period = gr.Textbox(label="Scenario Time Period", placeholder="Enter time period for the scenario")
|
| 110 |
+
scenario_objective = gr.Textbox(label="Scenario Objective", placeholder="Enter the objective of the scenario")
|
| 111 |
+
scenario_events = gr.Textbox(label="Scenario Events", placeholder="Enter major events in the scenario")
|
| 112 |
+
scenario_rules = gr.Textbox(label="Scenario Rules", placeholder="Enter any rules or restrictions for the scenario")
|
| 113 |
+
|
| 114 |
+
scenario_summarize_button = gr.Button("Summarize Scenario Details")
|
| 115 |
+
scenario_summary_output = gr.Textbox(label="Scenario Summary")
|
| 116 |
+
|
| 117 |
+
scenario_summarize_button.click(
|
| 118 |
+
summarize_scenario,
|
| 119 |
+
[scenario_setting, scenario_time_period, scenario_objective, scenario_events, scenario_rules],
|
| 120 |
+
scenario_summary_output
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
with gr.Column():
|
| 124 |
+
gr.Markdown("### AI Rules")
|
| 125 |
+
ai_rules_input = gr.Textbox(label="AI Rules", placeholder="Enter rules for AI behavior")
|
| 126 |
+
|
| 127 |
+
ai_rules_summarize_button = gr.Button("Summarize AI Rules")
|
| 128 |
+
ai_rules_summary_output = gr.Textbox(label="AI Rules Summary")
|
| 129 |
+
|
| 130 |
+
ai_rules_summarize_button.click(
|
| 131 |
+
summarize_ai_rules,
|
| 132 |
+
[ai_rules_input],
|
| 133 |
+
ai_rules_summary_output
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
with gr.Tab("Generate Scenario"):
|
| 137 |
+
gr.Markdown("### Dynamic Scenario Generation")
|
| 138 |
+
gr.Markdown("This will generate a scenario description based on the details you provided.")
|
| 139 |
+
gen_scenario_button = gr.Button("Generate Scenario")
|
| 140 |
+
generated_scenario_output = gr.Textbox(label="Generated Scenario")
|
| 141 |
+
|
| 142 |
+
# Triggering the scenario generation
|
| 143 |
+
gen_scenario_button.click(
|
| 144 |
+
generate_scenario,
|
| 145 |
+
[scenario_setting, scenario_time_period, scenario_objective, scenario_events, scenario_rules],
|
| 146 |
+
generated_scenario_output
|
| 147 |
+
)
|
| 148 |
|
| 149 |
gradio_app.launch()
|